cgen,js: fix missing break in switch case, generated by match with range branches (#12260)
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--
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
4..5
|
|
@ -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