Fix as pattern formatting inside apply

This commit is contained in:
Joshua Warner 2024-12-10 17:57:28 -08:00
parent f8b0be725c
commit 04612fb2cb
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 48 additions and 1 deletions

View file

@ -395,7 +395,7 @@ fn fmt_pattern_only(
}
Pattern::As(pattern, pattern_as) => {
let needs_parens = parens == Parens::InAsPattern;
let needs_parens = parens == Parens::InAsPattern || parens == Parens::InApply;
if needs_parens {
buf.indent(indent);

View file

@ -0,0 +1,2 @@
when t is
Ok ({} as d) -> S

View file

@ -0,0 +1,42 @@
@0-29 SpaceAfter(
When(
@5-6 Var {
module_name: "",
ident: "t",
},
[
WhenBranch {
patterns: [
@14-25 SpaceBefore(
Apply(
@14-16 Tag(
"Ok",
),
[
@18-25 As(
@18-20 RecordDestructure(
[],
),
PatternAs {
spaces_before: [],
identifier: @24-25 "d",
},
),
],
),
[
Newline,
],
),
],
value: @28-29 Tag(
"S",
),
guard: None,
},
],
),
[
Newline,
],
)

View file

@ -0,0 +1,2 @@
when t is
Ok ({} as d)->S

View file

@ -564,6 +564,7 @@ mod test_snapshots {
pass/pattern_as_spaces.expr,
pass/pattern_comma_newlines.expr,
pass/pattern_record_apply_comment.expr,
pass/pattern_with_as_parens.expr,
pass/pattern_with_space_in_parens.expr, // https://github.com/roc-lang/roc/issues/929
pass/pizza_dbg.expr,
pass/pizza_question.moduledefs,