From 31636fbc9bbdbc93d86a8fdbeff572c1daf901ad Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Sat, 13 Dec 2025 16:31:02 +0800 Subject: [PATCH] checker: remove () from match branch exprs (fix #25950) (#25952) --- vlib/v/checker/match.v | 5 ++++ vlib/v/tests/match_branch_par_expr_test.v | 32 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 vlib/v/tests/match_branch_par_expr_test.v diff --git a/vlib/v/checker/match.v b/vlib/v/checker/match.v index c6c26989e..2dd1d8e56 100644 --- a/vlib/v/checker/match.v +++ b/vlib/v/checker/match.v @@ -238,6 +238,11 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type { } } + for mut expr in branch.exprs { + // (expr) => expr + expr = expr.remove_par() + } + if !c.pref.translated && !c.file.is_translated { // check for always true/false match branch for mut expr in branch.exprs { diff --git a/vlib/v/tests/match_branch_par_expr_test.v b/vlib/v/tests/match_branch_par_expr_test.v new file mode 100644 index 000000000..8a2082fe8 --- /dev/null +++ b/vlib/v/tests/match_branch_par_expr_test.v @@ -0,0 +1,32 @@ +module main + +enum TokenType { + null + word + get_word + set_word + lit_word + int_value + dec_value + bin_value + str_value + block_start + block_end + expr_start + expr_end + comment +} + +fn test_match_branch_par_expr() { + t := TokenType.word + s := match t { + (TokenType.null) { '' } + (TokenType.word) { 'a' } + (TokenType.get_word) { 'b' } + (TokenType.set_word) { 'c' } + (TokenType.lit_word) { 'd' } + else { 'other' } + } + + assert s == 'a' +} -- 2.39.5