diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 94acb59007..3667b42a3a 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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 } } diff --git a/vlib/v/tests/match_in_map_or_expr_test .v b/vlib/v/tests/match_in_map_or_expr_test .v new file mode 100644 index 0000000000..6f80725947 --- /dev/null +++ b/vlib/v/tests/match_in_map_or_expr_test .v @@ -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' +}