Skip to content

Commit 31636fb

Browse files
authored
checker: remove () from match branch exprs (fix #25950) (#25952)
1 parent 4682ee7 commit 31636fb

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

vlib/v/checker/match.v

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
238238
}
239239
}
240240

241+
for mut expr in branch.exprs {
242+
// (expr) => expr
243+
expr = expr.remove_par()
244+
}
245+
241246
if !c.pref.translated && !c.file.is_translated {
242247
// check for always true/false match branch
243248
for mut expr in branch.exprs {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module main
2+
3+
enum TokenType {
4+
null
5+
word
6+
get_word
7+
set_word
8+
lit_word
9+
int_value
10+
dec_value
11+
bin_value
12+
str_value
13+
block_start
14+
block_end
15+
expr_start
16+
expr_end
17+
comment
18+
}
19+
20+
fn test_match_branch_par_expr() {
21+
t := TokenType.word
22+
s := match t {
23+
(TokenType.null) { '' }
24+
(TokenType.word) { 'a' }
25+
(TokenType.get_word) { 'b' }
26+
(TokenType.set_word) { 'c' }
27+
(TokenType.lit_word) { 'd' }
28+
else { 'other' }
29+
}
30+
31+
assert s == 'a'
32+
}

0 commit comments

Comments
 (0)