mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Fix formatting issue with closures hiding in unary ops
This commit is contained in:
parent
8f0566a55f
commit
2464ce6856
5 changed files with 68 additions and 4 deletions
|
@ -1313,13 +1313,21 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
|
||||||
after: right_lifted.after,
|
after: right_lifted.after,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::UnaryOp(expr, op) => {
|
Expr::UnaryOp(inner, op) => {
|
||||||
let expr_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &expr.value);
|
if parens == Parens::InApply && matches!(inner.without_spaces(), Expr::Closure(..)) {
|
||||||
|
return Spaces {
|
||||||
|
before: &[],
|
||||||
|
item: Expr::ParensAround(arena.alloc(*expr)),
|
||||||
|
after: &[],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let inner_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &inner.value);
|
||||||
|
|
||||||
Spaces {
|
Spaces {
|
||||||
before: &[],
|
before: &[],
|
||||||
item: Expr::UnaryOp(arena.alloc(Loc::at(expr.region, expr_lifted.item)), *op),
|
item: Expr::UnaryOp(arena.alloc(Loc::at(inner.region, inner_lifted.item)), *op),
|
||||||
after: expr_lifted.after,
|
after: inner_lifted.after,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
m
|
||||||
|
^ (-\w -> m)
|
||||||
|
w
|
|
@ -0,0 +1,49 @@
|
||||||
|
@0-14 SpaceAfter(
|
||||||
|
BinOps(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
@0-1 SpaceAfter(
|
||||||
|
Var {
|
||||||
|
module_name: "",
|
||||||
|
ident: "m",
|
||||||
|
},
|
||||||
|
[
|
||||||
|
Newline,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
@3-4 Caret,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
@5-14 Apply(
|
||||||
|
@5-11 UnaryOp(
|
||||||
|
@6-11 Closure(
|
||||||
|
[
|
||||||
|
@7-8 Identifier {
|
||||||
|
ident: "w",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
@10-11 Var {
|
||||||
|
module_name: "",
|
||||||
|
ident: "m",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
@5-6 Negate,
|
||||||
|
),
|
||||||
|
[
|
||||||
|
@13-14 SpaceBefore(
|
||||||
|
Var {
|
||||||
|
module_name: "",
|
||||||
|
ident: "w",
|
||||||
|
},
|
||||||
|
[
|
||||||
|
Newline,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
Space,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
[
|
||||||
|
Newline,
|
||||||
|
],
|
||||||
|
)
|
|
@ -0,0 +1,3 @@
|
||||||
|
m
|
||||||
|
^ -\w->m
|
||||||
|
w
|
|
@ -355,6 +355,7 @@ mod test_snapshots {
|
||||||
pass/closure_newline_empty_record_newline.expr,
|
pass/closure_newline_empty_record_newline.expr,
|
||||||
pass/closure_parens_double_newlines.expr,
|
pass/closure_parens_double_newlines.expr,
|
||||||
pass/closure_pat_reccord_comment.expr,
|
pass/closure_pat_reccord_comment.expr,
|
||||||
|
pass/closure_with_binops_and_unary.expr,
|
||||||
pass/closure_with_underscores.expr,
|
pass/closure_with_underscores.expr,
|
||||||
pass/comma_prefixed_indented_record.expr,
|
pass/comma_prefixed_indented_record.expr,
|
||||||
pass/comment_after_annotation.expr,
|
pass/comment_after_annotation.expr,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue