mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Disallow eliding empty record destructure assignment if expr looks like an implements clause (fixes #7366)
This commit is contained in:
parent
f86f440f2f
commit
c54b01016e
7 changed files with 91 additions and 3 deletions
|
@ -1049,6 +1049,7 @@ pub fn fmt_body<'a>(
|
|||
&& !matches!(body.extract_spaces().item, Expr::Defs(..))
|
||||
&& !matches!(body.extract_spaces().item, Expr::Return(..))
|
||||
&& !starts_with_expect_ident(body)
|
||||
&& !might_be_confused_with_implements(body)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
@ -1172,6 +1173,34 @@ fn starts_with_expect_ident(expr: &Expr<'_>) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn might_be_confused_with_implements(body: &Expr<'_>) -> bool {
|
||||
// As with `expect`, we need to be careful about things that might "become" `implements` clauses
|
||||
// if parsed at a statement level.
|
||||
match body {
|
||||
Expr::Apply(func, args, _) => {
|
||||
if !matches!(func.extract_spaces().item, Expr::Tag(..)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for expr in *args {
|
||||
match expr.extract_spaces().item {
|
||||
Expr::Var { module_name, ident } => {
|
||||
if module_name.is_empty()
|
||||
&& (ident == "implements" || ident == "implements!")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn starts_with_block_string_literal(expr: &Expr<'_>) -> bool {
|
||||
match expr {
|
||||
Expr::Str(s) => is_str_multiline(s),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue