cgen: fix error of nested match expr (#12334)

pull/12360/head
yuyi 2021-10-29 22:14:49 +08:00 committed by GitHub
parent 71392111f8
commit d5642b6134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -1557,7 +1557,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
// } // }
old_is_void_expr_stmt := g.is_void_expr_stmt old_is_void_expr_stmt := g.is_void_expr_stmt
g.is_void_expr_stmt = !node.is_expr g.is_void_expr_stmt = !node.is_expr
if node.typ != ast.void_type && g.expected_cast_type != 0 { if node.typ != ast.void_type && g.expected_cast_type != 0 && node.expr !is ast.MatchExpr {
g.expr_with_cast(node.expr, node.typ, g.expected_cast_type) g.expr_with_cast(node.expr, node.typ, g.expected_cast_type)
} else { } else {
g.expr(node.expr) g.expr(node.expr)

View File

@ -0,0 +1,35 @@
struct Abc {}
type Test = Abc | bool | int
fn test(a Test) Test {
return match a {
Abc {
20
}
int {
match a {
1 { true }
2 { false }
else { -1 }
}
}
bool {
1
}
}
}
fn test_nested_match_expr() {
println(test(1))
assert test(1) == Test(true)
println(test(2))
assert test(2) == Test(false)
println(test(3))
assert test(3) == Test(-1)
println(test(true))
assert test(true) == Test(1)
}