Expand handling of guard_needs_parens

This commit is contained in:
Joshua Warner 2025-01-14 20:59:35 -08:00
parent 7f1b3449a6
commit d42af0b763
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
7 changed files with 125 additions and 13 deletions

View file

@ -0,0 +1,12 @@
when
f
is
3 if (|t|
m
%
when
f
is
z ->
e
z) -> m

View file

@ -0,0 +1,93 @@
@0-40 SpaceAfter(
When(
@5-6 SpaceAfter(
Var {
module_name: "",
ident: "f",
},
[
Newline,
],
),
[
WhenBranch {
patterns: [
@10-11 SpaceBefore(
NumLiteral(
"3",
),
[
Newline,
],
),
],
value: @39-40 Var {
module_name: "",
ident: "m",
},
guard: Some(
@14-37 Closure(
[
@15-16 Identifier {
ident: "t",
},
],
@18-37 BinOps(
[
(
@18-19 Var {
module_name: "",
ident: "m",
},
@19-20 Percent,
),
],
@20-37 When(
@25-26 SpaceAfter(
Var {
module_name: "",
ident: "f",
},
[
Newline,
],
),
[
WhenBranch {
patterns: [
@30-31 Identifier {
ident: "z",
},
],
value: @33-37 Apply(
@33-34 Var {
module_name: "",
ident: "e",
},
[
@36-37 SpaceBefore(
Var {
module_name: "",
ident: "z",
},
[
Newline,
],
),
],
Space,
),
guard: None,
},
],
),
),
),
),
},
],
),
[
Newline,
],
)

View file

@ -0,0 +1,5 @@
when f
is
3 if\t->m%when f
is z->e
z->m

View file

@ -777,6 +777,7 @@ mod test_snapshots {
pass/when_if_guard.expr,
pass/when_in_assignment.expr,
pass/when_in_binop_in_assign_with_sneaky_newline.expr,
pass/when_in_binop_in_closure_in_when_guard_wow_fuzzer.expr,
pass/when_in_binops.expr,
pass/when_in_closure_in_when_guard_wtf.expr,
pass/when_in_function.expr,