diff --git a/vlib/v/fmt/tests/match_expected.vv b/vlib/v/fmt/tests/match_expected.vv index 556768f95c..182cb70043 100644 --- a/vlib/v/fmt/tests/match_expected.vv +++ b/vlib/v/fmt/tests/match_expected.vv @@ -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 {} + } +} diff --git a/vlib/v/fmt/tests/match_input.vv b/vlib/v/fmt/tests/match_input.vv index 3f7cbae675..18ac19dbfd 100644 --- a/vlib/v/fmt/tests/match_input.vv +++ b/vlib/v/fmt/tests/match_input.vv @@ -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 {} + } +} diff --git a/vlib/v/parser/if_match.v b/vlib/v/parser/if_match.v index 2ad526fc5a..194f868675 100644 --- a/vlib/v/parser/if_match.v +++ b/vlib/v/parser/if_match.v @@ -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()