1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix the C codegen error for '_ = map[key]' (fix #11999) (#12000)

This commit is contained in:
yuyi 2021-09-28 23:45:50 +08:00 committed by GitHub
parent 86694ddc85
commit 5d3795e876
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -2925,6 +2925,9 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
g.right_is_opt = true
}
if blank_assign {
if val is ast.IndexExpr {
g.assign_op = .decl_assign
}
if is_call {
old_is_void_expr_stmt := g.is_void_expr_stmt
g.is_void_expr_stmt = true

View File

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