cgen,js: fix missing break in switch case, generated by match with range branches (#12260)

pull/12266/head
ChAoS_UnItY 2021-10-22 03:30:05 +08:00 committed by GitHub
parent da7dad07a3
commit 5b69593766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 3 deletions

View File

@ -4480,6 +4480,7 @@ fn (mut g Gen) match_expr_switch(node ast.MatchExpr, is_expr bool, cond_var stri
} }
g.writeln(') {') g.writeln(') {')
g.stmts_with_tmp_var(range_branch.stmts, tmp_var) g.stmts_with_tmp_var(range_branch.stmts, tmp_var)
g.writeln('break;')
g.writeln('}') g.writeln('}')
} }
g.indent-- 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.writeln(') {')
g.stmts_with_tmp_var(range_branch.stmts, tmp_var) g.stmts_with_tmp_var(range_branch.stmts, tmp_var)
g.writeln('break;')
g.writeln('}') g.writeln('}')
} }
g.indent-- g.indent--

View File

@ -0,0 +1 @@
4..5

View File

@ -8,13 +8,17 @@ enum Enum {
} }
fn main() { fn main() {
e := Enum.e1 e := Enum.e5
match e { match e {
.e1 {} .e1 {}
.e2 {} .e2 {}
.e3 {} .e3 {}
.e4 {} .e4 {}
4...5 {} 4...5 {
else {} println('4..5')
}
else {
println('else')
}
} }
} }

View File

@ -2362,6 +2362,7 @@ fn (mut g JsGen) match_expr_switch(node ast.MatchExpr, is_expr bool, cond_var Ma
} }
g.writeln(') {') g.writeln(') {')
g.stmts_with_tmp_var(range_branch.stmts, tmp_var) g.stmts_with_tmp_var(range_branch.stmts, tmp_var)
g.writeln('break;')
g.writeln('}') g.writeln('}')
} }
g.dec_indent() 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.writeln(') {')
g.stmts_with_tmp_var(range_branch.stmts, tmp_var) g.stmts_with_tmp_var(range_branch.stmts, tmp_var)
g.writeln('break;')
g.writeln('}') g.writeln('}')
} }
g.dec_indent() g.dec_indent()