cgen: fix match for one branch (#9234)

pull/9238/head
Swastik Baranwal 2021-03-10 22:14:32 +05:30 committed by GitHub
parent eefdad21c7
commit 8d84206a8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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) 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('}') g.write('}')
} }
} }

View File

@ -0,0 +1,12 @@
enum Color {
red
}
fn test_match_one_branch() {
col := Color.red
match col {
.red {
assert true
}
}
}