cgen: fix codegen for indexing anon_fn (fix #23493) (#23495)

This commit is contained in:
Felipe Pena 2025-01-17 10:31:39 -03:00 committed by GitHub
parent d5aa37d8b7
commit 3b0cfbfd0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View File

@ -444,7 +444,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
g.is_assign_lhs = false
g.is_arraymap_set = false
if mut left is ast.IndexExpr {
sym := g.table.sym(left.left_type)
sym := g.table.final_sym(left.left_type)
if sym.kind in [.map, .array] {
g.expr(val)
g.writeln('});')

View File

@ -0,0 +1,21 @@
module main
pub struct Tree {}
pub type TreeBelt = map[string]fn (input &Tree, belt TreeBelt) []&Tree
pub fn (tree &Tree) processed() TreeBelt {
mut blet := TreeBelt(map[string]fn (&Tree, TreeBelt) []&Tree{})
blet['foo'] = fn (input &Tree, belt TreeBelt) []&Tree {
return [input]
}
return blet
}
fn test_main() {
tree := Tree{}
ret := tree.processed()
assert ret.len == 1
ret2 := ret['foo'](tree, ret)
assert ret2[0] == tree
}