mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-27 19:46:10 +00:00
Fix more cases of when in guard
This commit is contained in:
parent
903b792fd3
commit
6b08f42d02
5 changed files with 99 additions and 0 deletions
|
|
@ -1779,6 +1779,8 @@ fn guard_needs_parens(value: &Expr<'_>) -> bool {
|
|||
Expr::ParensAround(expr) | Expr::SpaceBefore(expr, _) | Expr::SpaceAfter(expr, _) => {
|
||||
guard_needs_parens(expr)
|
||||
}
|
||||
Expr::Closure(_, body) => guard_needs_parens(&body.value),
|
||||
Expr::Defs(_, final_expr) => guard_needs_parens(&final_expr.value),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
when
|
||||
f
|
||||
is
|
||||
s if (\t ->
|
||||
when
|
||||
0
|
||||
is
|
||||
z ->
|
||||
f
|
||||
z) -> m
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
@0-38 SpaceAfter(
|
||||
When(
|
||||
@5-6 SpaceAfter(
|
||||
Var {
|
||||
module_name: "",
|
||||
ident: "f",
|
||||
},
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
[
|
||||
WhenBranch {
|
||||
patterns: [
|
||||
@10-11 SpaceBefore(
|
||||
Identifier {
|
||||
ident: "s",
|
||||
},
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
],
|
||||
value: @37-38 Var {
|
||||
module_name: "",
|
||||
ident: "m",
|
||||
},
|
||||
guard: Some(
|
||||
@14-35 Closure(
|
||||
[
|
||||
@15-16 Identifier {
|
||||
ident: "t",
|
||||
},
|
||||
],
|
||||
@18-35 When(
|
||||
@23-24 SpaceAfter(
|
||||
Num(
|
||||
"0",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
[
|
||||
WhenBranch {
|
||||
patterns: [
|
||||
@28-29 Identifier {
|
||||
ident: "z",
|
||||
},
|
||||
],
|
||||
value: @31-35 Apply(
|
||||
@31-32 Var {
|
||||
module_name: "",
|
||||
ident: "f",
|
||||
},
|
||||
[
|
||||
@34-35 SpaceBefore(
|
||||
Var {
|
||||
module_name: "",
|
||||
ident: "z",
|
||||
},
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
],
|
||||
Space,
|
||||
),
|
||||
guard: None,
|
||||
},
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
when f
|
||||
is
|
||||
s if\t->when 0
|
||||
is z->f
|
||||
z->m
|
||||
|
|
@ -759,6 +759,7 @@ mod test_snapshots {
|
|||
pass/when_if_guard.expr,
|
||||
pass/when_in_assignment.expr,
|
||||
pass/when_in_binops.expr,
|
||||
pass/when_in_closure_in_when_guard_wtf.expr,
|
||||
pass/when_in_function.expr,
|
||||
pass/when_in_function_python_style_indent.expr,
|
||||
pass/when_in_list.expr,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue