mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix anon_fn in containers (#9077)
This commit is contained in:
parent
dd475f4e37
commit
97f9abcf82
@ -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] {
|
||||
|
@ -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'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user