fmt: remove extra comma of branch instead of parse error (#12814)

pull/12831/head weekly.2021.50.1
zakuro 2021-12-14 15:14:43 +09:00 committed by GitHub
parent 731015cd9b
commit eed882950c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 0 deletions

View File

@ -36,3 +36,15 @@ fn really_long_branch_exprs() {
}
}
}
fn match_branch_extra_comma() {
match x {
Foo, Bar {}
int, string {}
}
match n {
0...5 {}
2, 3 {}
else {}
}
}

View File

@ -34,3 +34,15 @@ fn really_long_branch_exprs() {
}
}
}
fn match_branch_extra_comma() {
match x {
Foo, Bar, {}
int,,, string, {}
}
match n {
0...5, {}
2, 3, {}
else {}
}
}

View File

@ -197,6 +197,14 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
break
}
p.check(.comma)
if p.pref.is_fmt {
if p.tok.kind == .lcbr {
break
}
for p.tok.kind == .comma {
p.next()
}
}
}
is_sum_type = true
} else {
@ -226,7 +234,16 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
if p.tok.kind != .comma {
break
}
p.check(.comma)
if p.pref.is_fmt {
if p.tok.kind == .lcbr {
break
}
for p.tok.kind == .comma {
p.next()
}
}
}
}
branch_last_pos := p.prev_tok.position()