cgen: fix anon_fn in containers (fix #8965) (#9049)

pull/9057/head
yuyi 2021-03-02 16:26:27 +08:00 committed by GitHub
parent 01735c67c6
commit 81dbd72412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -1952,7 +1952,18 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
g.definitions.go_back(g.definitions.len - def_pos)
g.write(') = ')
} else {
g.is_assign_lhs = true
g.assign_op = assign_stmt.op
g.expr(left)
g.is_assign_lhs = false
if left is ast.IndexExpr {
sym := g.table.get_type_symbol(left.left_type)
if sym.kind in [.map, .array] {
g.expr(val)
g.writeln('});')
continue
}
}
g.write(' = ')
}
g.expr(val)

View File

@ -0,0 +1,13 @@
fn test_anon_fn_in_map() {
mut woop := map{
'what': fn() string {
return 'whoopity whoop'
}
}
assert woop['what']() == 'whoopity whoop'
woop['shat'] = fn() string {
return 'shoopity shoop'
}
assert woop['shat']() == 'shoopity shoop'
}