mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen,js: fix missing break in switch case, generated by match with range branches (#12260)
This commit is contained in:
parent
da7dad07a3
commit
5b69593766
@ -4480,6 +4480,7 @@ fn (mut g Gen) match_expr_switch(node ast.MatchExpr, is_expr bool, cond_var stri
|
||||
}
|
||||
g.writeln(') {')
|
||||
g.stmts_with_tmp_var(range_branch.stmts, tmp_var)
|
||||
g.writeln('break;')
|
||||
g.writeln('}')
|
||||
}
|
||||
g.indent--
|
||||
@ -4543,6 +4544,7 @@ fn (mut g Gen) match_expr_switch(node ast.MatchExpr, is_expr bool, cond_var stri
|
||||
}
|
||||
g.writeln(') {')
|
||||
g.stmts_with_tmp_var(range_branch.stmts, tmp_var)
|
||||
g.writeln('break;')
|
||||
g.writeln('}')
|
||||
}
|
||||
g.indent--
|
||||
|
1
vlib/v/gen/c/testdata/enum_switch_case.out
vendored
Normal file
1
vlib/v/gen/c/testdata/enum_switch_case.out
vendored
Normal file
@ -0,0 +1 @@
|
||||
4..5
|
10
vlib/v/gen/c/testdata/enum_switch_case.vv
vendored
10
vlib/v/gen/c/testdata/enum_switch_case.vv
vendored
@ -8,13 +8,17 @@ enum Enum {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
e := Enum.e1
|
||||
e := Enum.e5
|
||||
match e {
|
||||
.e1 {}
|
||||
.e2 {}
|
||||
.e3 {}
|
||||
.e4 {}
|
||||
4...5 {}
|
||||
else {}
|
||||
4...5 {
|
||||
println('4..5')
|
||||
}
|
||||
else {
|
||||
println('else')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2362,6 +2362,7 @@ fn (mut g JsGen) match_expr_switch(node ast.MatchExpr, is_expr bool, cond_var Ma
|
||||
}
|
||||
g.writeln(') {')
|
||||
g.stmts_with_tmp_var(range_branch.stmts, tmp_var)
|
||||
g.writeln('break;')
|
||||
g.writeln('}')
|
||||
}
|
||||
g.dec_indent()
|
||||
@ -2423,6 +2424,7 @@ fn (mut g JsGen) match_expr_switch(node ast.MatchExpr, is_expr bool, cond_var Ma
|
||||
}
|
||||
g.writeln(') {')
|
||||
g.stmts_with_tmp_var(range_branch.stmts, tmp_var)
|
||||
g.writeln('break;')
|
||||
g.writeln('}')
|
||||
}
|
||||
g.dec_indent()
|
||||
|
Loading…
Reference in New Issue
Block a user