Merge pull request #6862 from JRI98/fix_6215

Fix handling of spaces after for `as`
This commit is contained in:
Luke Boswell 2024-07-08 08:51:53 +10:00 committed by GitHub
commit 1d1b96abb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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)) => {
let region = Region::span_across(&pattern.region, &pattern_as.identifier.region);
let pattern = arena
.alloc(pattern.value)
.with_spaces_after(pattern_spaces, pattern.region);
let mut pattern = pattern;
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);
Ok((MadeProgress, Loc::at(region, as_pattern), state))

View File

@ -7,11 +7,8 @@ When(
patterns: [
@14-20 SpaceBefore(
As(
@14-15 SpaceAfter(
Underscore(
"",
),
[],
@14-15 Underscore(
"",
),
PatternAs {
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
// #[test]
// fn multiline_apply() {