mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-01 21:40:58 +00:00
Fix unary op parens in the case of closure
This commit is contained in:
parent
bf3fae4827
commit
2918e26b38
5 changed files with 55 additions and 1 deletions
|
|
@ -266,7 +266,8 @@ fn format_expr_only(
|
|||
Expr::Apply(..) | Expr::BinOps(..) | Expr::Defs(..)
|
||||
)
|
||||
|| (matches!(unary_op.value, called_via::UnaryOp::Negate)
|
||||
&& requires_space_after_unary(&lifted.item));
|
||||
&& requires_space_after_unary(&lifted.item))
|
||||
|| (parens == Parens::InApply && ends_with_closure(&lifted.item));
|
||||
|
||||
if needs_parens {
|
||||
// Unary negation can't be followed by whitespace (which is what a newline is) - so
|
||||
|
|
@ -1467,6 +1468,7 @@ fn fmt_binops<'a>(
|
|||
fn ends_with_closure(item: &Expr<'_>) -> bool {
|
||||
match item {
|
||||
Expr::Closure(..) => true,
|
||||
Expr::UnaryOp(inner, _) => ends_with_closure(&inner.value),
|
||||
Expr::Apply(expr, args, _) => args
|
||||
.last()
|
||||
.map(|a| ends_with_closure(&a.value))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
[
|
||||
[
|
||||
!(!\L -> t)
|
||||
M,
|
||||
],
|
||||
]
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
@0-13 SpaceAfter(
|
||||
List(
|
||||
[
|
||||
@1-12 List(
|
||||
[
|
||||
@2-11 Apply(
|
||||
@2-9 UnaryOp(
|
||||
@3-9 UnaryOp(
|
||||
@4-9 Closure(
|
||||
[
|
||||
@5-6 Tag(
|
||||
"L",
|
||||
),
|
||||
],
|
||||
@8-9 Var {
|
||||
module_name: "",
|
||||
ident: "t",
|
||||
},
|
||||
),
|
||||
@3-4 Not,
|
||||
),
|
||||
@2-3 Not,
|
||||
),
|
||||
[
|
||||
@10-11 SpaceBefore(
|
||||
Tag(
|
||||
"M",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
],
|
||||
Space,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
[[!!\L->t
|
||||
M]]
|
||||
|
|
@ -486,6 +486,7 @@ mod test_snapshots {
|
|||
pass/list_closing_same_indent_with_trailing_comma.expr,
|
||||
pass/list_comma_newlines.expr,
|
||||
pass/list_comment_newline.expr,
|
||||
pass/list_list_not_not_closure_newline.expr,
|
||||
pass/list_lots_of_spaces.expr,
|
||||
pass/list_minus_newlines.expr,
|
||||
pass/list_pattern_weird_indent.expr,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue