cgen: fix map get assign blank var with optional (#12943)
parent
b88a40ad80
commit
ad1ef6a9e2
|
@ -197,6 +197,7 @@ fn (mut g Gen) gen_assign_stmt(node ast.AssignStmt) {
|
||||||
if val is ast.IndexExpr {
|
if val is ast.IndexExpr {
|
||||||
g.assign_op = .decl_assign
|
g.assign_op = .decl_assign
|
||||||
}
|
}
|
||||||
|
g.is_assign_lhs = false
|
||||||
if is_call {
|
if is_call {
|
||||||
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 = true
|
g.is_void_expr_stmt = true
|
||||||
|
@ -209,7 +210,6 @@ fn (mut g Gen) gen_assign_stmt(node ast.AssignStmt) {
|
||||||
g.expr(val)
|
g.expr(val)
|
||||||
g.writeln(';}')
|
g.writeln(';}')
|
||||||
}
|
}
|
||||||
g.is_assign_lhs = false
|
|
||||||
} else if node.op == .assign
|
} else if node.op == .assign
|
||||||
&& (is_fixed_array_init || (right_sym.kind == .array_fixed && val is ast.Ident)) {
|
&& (is_fixed_array_init || (right_sym.kind == .array_fixed && val is ast.Ident)) {
|
||||||
mut v_var := ''
|
mut v_var := ''
|
||||||
|
|
|
@ -17,3 +17,16 @@ fn test_map_get_assign_blank() {
|
||||||
}
|
}
|
||||||
assert true
|
assert true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_value() int {
|
||||||
|
mut m := map[string]int{}
|
||||||
|
_ := m['a'] or { return 1 }
|
||||||
|
println('a')
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_map_get_assign_blank_with_or_expr() {
|
||||||
|
ret := get_value()
|
||||||
|
println(ret)
|
||||||
|
assert ret == 1
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue