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

yuyi 2022-04-21 18:02:31 +08:00 committed by Jef Roosens
parent 052c8e0282
commit dc9068b4d3
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
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
}