Skip to content

Commit f5a5574

Browse files
authored
cgen: fix match codegen for option match case (fix #25533) (#25537)
1 parent a186e44 commit f5a5574

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎vlib/v/gen/c/match.v‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,10 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str
431431
node_cond_type_unsigned := node.cond_type in [ast.u16_type, ast.u32_type, ast.u64_type]
432432
type_sym := g.table.final_sym(node.cond_type)
433433
use_ternary := is_expr && tmp_var == ''
434-
mut reset_if := false
434+
mut reset_if := node.branches.any(it.exprs.any(g.match_must_reset_if(it)))
435435
mut has_goto := false
436436
for j, branch in node.branches {
437437
is_last := j == node.branches.len - 1
438-
reset_if = branch.exprs.any(g.match_must_reset_if(it))
439438
if reset_if {
440439
g.writeln('')
441440
g.set_current_pos_as_last_stmt_pos()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
enum A_ {
2+
b
3+
c
4+
d
5+
e
6+
}
7+
8+
fn test_main() {
9+
mut a := ?A_(none)
10+
a = .c
11+
match true {
12+
a == ?A_(.b) {
13+
assert false
14+
}
15+
a == ?A_(.c) {
16+
assert true
17+
}
18+
a == ?A_(.d) {
19+
assert false
20+
}
21+
else {
22+
assert false
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)