mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Don't remove empty record assignment if body looks like an expect
This commit is contained in:
parent
a1d61c5a3c
commit
d82accf83d
5 changed files with 70 additions and 0 deletions
|
@ -1034,6 +1034,7 @@ pub fn fmt_body<'a>(
|
|||
&& pattern_extracted.after.iter().all(|s| s.is_newline())
|
||||
&& !matches!(body.extract_spaces().item, Expr::Defs(..))
|
||||
&& !matches!(body.extract_spaces().item, Expr::Return(..))
|
||||
&& !starts_with_expect_ident(body)
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
@ -1144,6 +1145,19 @@ pub fn fmt_body<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
fn starts_with_expect_ident(expr: &Expr<'_>) -> bool {
|
||||
// We need to be persnickety about not formatting `{}=expect foo` into `expect foo`,
|
||||
// because `expect` is treated as a keyword at the statement level but not at the expr level.
|
||||
// If we removed the `{}=` in this case, that would change the meaning
|
||||
match expr {
|
||||
Expr::Apply(inner, _, _) => starts_with_expect_ident(&inner.value),
|
||||
Expr::Var { module_name, ident } => {
|
||||
module_name.is_empty() && (*ident == "expect" || *ident == "expect!")
|
||||
}
|
||||
_ => 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