cgen: fix error for if expr with nested match expr (#14122)

master
yuyi 2022-04-21 18:02:31 +08:00 committed by GitHub
parent 448938be0d
commit 8a18f9175a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -20,6 +20,9 @@ fn (mut g Gen) need_tmp_var_in_if(node ast.IfExpr) bool {
if is_noreturn_callexpr(stmt.expr) {
return true
}
if stmt.expr is ast.MatchExpr {
return true
}
if stmt.expr is ast.CallExpr {
if stmt.expr.is_method {
left_sym := g.table.sym(stmt.expr.receiver_type)

View File

@ -0,0 +1,12 @@
fn test_if_expr_with_nested_match_expr() {
a := if true {
match `a` {
`a` { 0 }
else { 1 }
}
} else {
3
}
println(a)
assert a == 0
}