cgen: fix array.map(anon_fn)
parent
895c7624e4
commit
d472a27489
|
@ -589,6 +589,13 @@ fn test_map() {
|
|||
assert strs == ['v', 'is', 'awesome']
|
||||
}
|
||||
|
||||
fn test_anon_fn_map() {
|
||||
add_num := fn (i int) int {
|
||||
return i + 1
|
||||
}
|
||||
assert [1,2,3].map(add_num) == [2,3,4]
|
||||
}
|
||||
|
||||
fn test_array_str() {
|
||||
numbers := [1, 2, 3]
|
||||
assert numbers == [1,2,3]
|
||||
|
|
|
@ -3175,7 +3175,15 @@ fn (mut g Gen) gen_map(node ast.CallExpr) {
|
|||
match node.args[0].expr {
|
||||
ast.Ident {
|
||||
if it.kind == .function {
|
||||
g.writeln('${it.name}(it)')
|
||||
g.write('${it.name}(it)')
|
||||
} else if it.kind == .variable {
|
||||
var_info := it.var_info()
|
||||
sym := g.table.get_type_symbol(var_info.typ)
|
||||
if sym.kind == .function {
|
||||
g.write('${it.name}(it)')
|
||||
} else {
|
||||
g.expr(node.args[0].expr)
|
||||
}
|
||||
} else {
|
||||
g.expr(node.args[0].expr)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue