cgen: fix match in map or expr (#10283)
parent
d39a55ac11
commit
9fc5b9dc54
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
}
|
Loading…
Reference in New Issue