0 issues 1 contributor 4 branches 0 releases
Additions: 33 Deletions: 0 View patch
1 if elem_sym.info is ast.FnType {
2 func = elem_sym.info.func
3 found = true
4+ node.is_fn_var = true
5+ node.fn_var_type = sym.info.elem_type
6 } else {
7 c.error('cannot call the element of the array, it is not a function',
8 node.pos)
9 if value_sym.info is ast.FnType {
10 func = value_sym.info.func
11 found = true
12+ node.is_fn_var = true
13+ node.fn_var_type = sym.info.value_type
14 } else {
15 c.error('cannot call the value of the map, it is not a function', node.pos)
16 }
17 if elem_sym.info is ast.FnType {
18 func = elem_sym.info.func
19 found = true
20+ node.is_fn_var = true
21+ node.fn_var_type = sym.info.elem_type
22 } else {
23 c.error('cannot call the element of the array, it is not a function',
24 node.pos)
25
1 g.gen_anon_fn_decl(mut expr.left)
2 name = expr.left.decl.name
3 }
4+ } else if expr.left is ast.IndexExpr {
5+ if expr.is_fn_var {
6+ fn_sym := g.table.sym(expr.fn_var_type)
7+ func := (fn_sym.info as ast.FnType).func
8+ fn_var := g.fn_var_signature(func.return_type, func.params.map(it.typ), tmp_fn)
9+ g.write('\t$fn_var = ')
10+ g.expr(expr.left)
11+ g.writeln(';')
12+ name = fn_sym.cname
13+ use_tmp_fn_var = true
14+ }
15 }
16 name = util.no_dots(name)
17 if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') {
18
1new file mode 100644
2+module main
3+
4+fn test_go_call_fn_using_map_value() {
5+ sum := fn (x int, y int) int {
6+ return x + y
7+ }
8+
9+ mut fns := map[string]fn (int, int) int{}
10+ fns['sum'] = sum
11+
12+ g := go fns['sum'](2, 3)
13+ x := g.wait()
14+
15+ println('$x')
16+ assert x == 5
17+}
18