mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Fix expr_lift_spaces of Closure
This commit is contained in:
parent
19f8cc532a
commit
cae47cf2a6
5 changed files with 49 additions and 6 deletions
|
@ -999,10 +999,24 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
|
||||||
after: final_expr_lifted.after,
|
after: final_expr_lifted.after,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::If { .. } | Expr::When(_, _) | Expr::Return(_, _) | Expr::Closure(..) => {
|
Expr::Closure(pats, body) => {
|
||||||
let res = if parens == Parens::InApply
|
if parens == Parens::InApply {
|
||||||
|| (parens == Parens::InApplyLastArg && !matches!(expr, Expr::Closure(..)))
|
return Spaces {
|
||||||
{
|
before: &[],
|
||||||
|
item: Expr::ParensAround(arena.alloc(*expr)),
|
||||||
|
after: &[],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let body_lifted = expr_lift_spaces_after(Parens::NotNeeded, arena, &body.value);
|
||||||
|
|
||||||
|
Spaces {
|
||||||
|
before: &[],
|
||||||
|
item: Expr::Closure(pats, arena.alloc(Loc::at(body.region, body_lifted.item))),
|
||||||
|
after: body_lifted.after,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Expr::If { .. } | Expr::When(_, _) | Expr::Return(_, _) => {
|
||||||
|
if parens == Parens::InApply || parens == Parens::InApplyLastArg {
|
||||||
Spaces {
|
Spaces {
|
||||||
before: &[],
|
before: &[],
|
||||||
item: Expr::ParensAround(arena.alloc(*expr)),
|
item: Expr::ParensAround(arena.alloc(*expr)),
|
||||||
|
@ -1014,8 +1028,7 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
|
||||||
item: *expr,
|
item: *expr,
|
||||||
after: &[],
|
after: &[],
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
dbg!(res)
|
|
||||||
}
|
}
|
||||||
Expr::Backpassing(pats, call, continuation) => {
|
Expr::Backpassing(pats, call, continuation) => {
|
||||||
let pats = arena.alloc_slice_copy(pats);
|
let pats = arena.alloc_slice_copy(pats);
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
\L -> E #
|
|
@ -0,0 +1,25 @@
|
||||||
|
SpaceAfter(
|
||||||
|
Closure(
|
||||||
|
[
|
||||||
|
@1-2 Tag(
|
||||||
|
"L",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
@4-10 ParensAround(
|
||||||
|
SpaceAfter(
|
||||||
|
Tag(
|
||||||
|
"E",
|
||||||
|
),
|
||||||
|
[
|
||||||
|
Newline,
|
||||||
|
LineComment(
|
||||||
|
"",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
[
|
||||||
|
Newline,
|
||||||
|
],
|
||||||
|
)
|
|
@ -0,0 +1,3 @@
|
||||||
|
\L->(E
|
||||||
|
#
|
||||||
|
)
|
|
@ -328,6 +328,7 @@ mod test_snapshots {
|
||||||
pass/body_with_unneeded_parens.expr,
|
pass/body_with_unneeded_parens.expr,
|
||||||
pass/call_bang.expr,
|
pass/call_bang.expr,
|
||||||
pass/call_bang_no_space.expr,
|
pass/call_bang_no_space.expr,
|
||||||
|
pass/capture_body_parens_comment.expr,
|
||||||
pass/closure_in_apply_in_binop.expr,
|
pass/closure_in_apply_in_binop.expr,
|
||||||
pass/closure_in_binop_with_spaces.expr,
|
pass/closure_in_binop_with_spaces.expr,
|
||||||
pass/closure_pat_reccord_comment.expr,
|
pass/closure_pat_reccord_comment.expr,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue