cgen: fix assign map get to blank (fix #11508) (#11982)

pull/11984/head
yuyi 2021-09-26 18:07:51 +08:00 committed by GitHub
parent 6391f3d2da
commit d93737dd34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -2748,6 +2748,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
g.expr(val)
g.writeln(';}')
}
g.is_assign_lhs = false
} else if assign_stmt.op == .assign
&& (is_fixed_array_init || (right_sym.kind == .array_fixed && val is ast.Ident)) {
mut v_var := ''

View File

@ -0,0 +1,10 @@
type Abc = int | string
fn test_map_get_assign_blank() {
x := map[string]Abc{}
_ := x['nonexisting']
if y := x['nonexisting'] {
println(y)
}
assert true
}