Fix handling of spaces after for as

This commit is contained in:
JRI98 2024-07-03 14:38:46 +01:00
parent 3abc276937
commit 25084b18ec
No known key found for this signature in database
GPG key ID: F83B29916FF13F24
3 changed files with 35 additions and 8 deletions

View file

@ -63,9 +63,14 @@ pub fn loc_pattern_help<'a>() -> impl Parser<'a, Loc<Pattern<'a>>, EPattern<'a>>
}, },
Ok((_, pattern_as, state)) => { Ok((_, pattern_as, state)) => {
let region = Region::span_across(&pattern.region, &pattern_as.identifier.region); let region = Region::span_across(&pattern.region, &pattern_as.identifier.region);
let pattern = arena
.alloc(pattern.value) let mut pattern = pattern;
.with_spaces_after(pattern_spaces, pattern.region); if !pattern_spaces.is_empty() {
pattern = arena
.alloc(pattern.value)
.with_spaces_after(pattern_spaces, pattern.region)
}
let as_pattern = Pattern::As(arena.alloc(pattern), pattern_as); let as_pattern = Pattern::As(arena.alloc(pattern), pattern_as);
Ok((MadeProgress, Loc::at(region, as_pattern), state)) Ok((MadeProgress, Loc::at(region, as_pattern), state))

View file

@ -7,11 +7,8 @@ When(
patterns: [ patterns: [
@14-20 SpaceBefore( @14-20 SpaceBefore(
As( As(
@14-15 SpaceAfter( @14-15 Underscore(
Underscore( "",
"",
),
[],
), ),
PatternAs { PatternAs {
spaces_before: [], spaces_before: [],

View file

@ -6113,6 +6113,31 @@ mod test_fmt {
); );
} }
#[test]
fn issue_6215() {
expr_formats_to(
indoc!(
r"
when list is
[first as last]
| [first, last] ->
first
_->Not
"
),
indoc!(
r"
when list is
[first as last]
| [first, last] ->
first
_ -> Not
"
),
);
}
// this is a parse error atm // this is a parse error atm
// #[test] // #[test]
// fn multiline_apply() { // fn multiline_apply() {