1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix match in map or expr (#10283)

This commit is contained in:
yuyi 2021-05-31 22:10:33 +08:00 committed by GitHub
parent d39a55ac11
commit 9fc5b9dc54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -4037,7 +4037,8 @@ fn (mut g Gen) need_tmp_var_in_match(node ast.MatchExpr) bool {
if branch.stmts[0] is ast.ExprStmt {
stmt := branch.stmts[0] as ast.ExprStmt
if stmt.expr is ast.CallExpr || stmt.expr is ast.IfExpr
|| stmt.expr is ast.MatchExpr {
|| stmt.expr is ast.MatchExpr || (stmt.expr is ast.IndexExpr
&& (stmt.expr as ast.IndexExpr).or_expr.kind != .absent) {
return true
}
}

View File

@ -0,0 +1,15 @@
fn test_match_in_map_or_expr() {
a := 5
some_map := map{
3: '3'
4: '4'
}
something := match a {
7 { '7' }
6 { '6' }
5 { '5' }
else { some_map[a] or { a.str() } } // here is the error
}
println(something)
assert something == '5'
}