cgen: fix map get assign blank var with optional (#12943)

pull/12945/head
yuyi 2021-12-23 19:04:36 +08:00 committed by GitHub
parent b88a40ad80
commit ad1ef6a9e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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 := ''

View File

@ -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
}