cgen: fix anon_fn in containers (#9077)

pull/9084/head
yuyi 2021-03-03 16:12:08 +08:00 committed by GitHub
parent dd475f4e37
commit 97f9abcf82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -1956,6 +1956,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
g.assign_op = assign_stmt.op
g.expr(left)
g.is_assign_lhs = false
g.is_array_set = false
if left is ast.IndexExpr {
sym := g.table.get_type_symbol(left.left_type)
if sym.kind in [.map, .array] {

View File

@ -11,3 +11,27 @@ fn test_anon_fn_in_map() {
}
assert woop['shat']() == 'shoopity shoop'
}
fn test_anon_fn_in_array() {
mut woop := [fn() string {
return 'whoopity whoop'
}]
assert woop[0]() == 'whoopity whoop'
woop[0] = fn() string {
return 'shoopity shoop'
}
assert woop[0]() == 'shoopity shoop'
}
fn test_anon_fn_in_fixed_array() {
mut woop := [fn() string {
return 'whoopity whoop'
}]!
assert woop[0]() == 'whoopity whoop'
woop[0] = fn() string {
return 'shoopity shoop'
}
assert woop[0]() == 'shoopity shoop'
}