mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix match for one branch (#9234)
This commit is contained in:
parent
eefdad21c7
commit
8d84206a8c
@ -3810,7 +3810,7 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str
|
||||
}
|
||||
}
|
||||
g.stmts_with_tmp_var(branch.stmts, tmp_var)
|
||||
if g.inside_ternary == 0 && node.branches.len > 1 {
|
||||
if g.inside_ternary == 0 && node.branches.len >= 1 {
|
||||
g.write('}')
|
||||
}
|
||||
}
|
||||
|
12
vlib/v/tests/match_expr_with_one_branch_test.v
Normal file
12
vlib/v/tests/match_expr_with_one_branch_test.v
Normal file
@ -0,0 +1,12 @@
|
||||
enum Color {
|
||||
red
|
||||
}
|
||||
|
||||
fn test_match_one_branch() {
|
||||
col := Color.red
|
||||
match col {
|
||||
.red {
|
||||
assert true
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user