From 8f7557f97a43e9f6d0d025f4a0c7f5d1683ce1e7 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Fri, 17 Jan 2025 07:12:34 -0300 Subject: [PATCH] fix --- vlib/v/gen/c/assign.v | 2 +- vlib/v/tests/indexexpr_with_anon_fn_test.v | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/indexexpr_with_anon_fn_test.v diff --git a/vlib/v/gen/c/assign.v b/vlib/v/gen/c/assign.v index a9435a8e831cce..58e3537371ae74 100644 --- a/vlib/v/gen/c/assign.v +++ b/vlib/v/gen/c/assign.v @@ -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('});') diff --git a/vlib/v/tests/indexexpr_with_anon_fn_test.v b/vlib/v/tests/indexexpr_with_anon_fn_test.v new file mode 100644 index 00000000000000..294e3cd44282ca --- /dev/null +++ b/vlib/v/tests/indexexpr_with_anon_fn_test.v @@ -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 +}