mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix array.map(fn...)
This commit is contained in:
parent
b3e416fb52
commit
85c741519b
@ -596,6 +596,14 @@ fn test_anon_fn_map() {
|
||||
assert [1,2,3].map(add_num) == [2,3,4]
|
||||
}
|
||||
|
||||
fn test_anon_fn_arg_map() {
|
||||
a := [1,2,3].map(fn (i int) int {
|
||||
return i + 1
|
||||
})
|
||||
|
||||
assert a == [2,3,4]
|
||||
}
|
||||
|
||||
fn test_array_str() {
|
||||
numbers := [1, 2, 3]
|
||||
assert numbers == [1,2,3]
|
||||
|
@ -3190,6 +3190,16 @@ fn (mut g Gen) gen_map(node ast.CallExpr) {
|
||||
g.expr(node.args[0].expr)
|
||||
}
|
||||
}
|
||||
ast.AnonFn {
|
||||
pos := g.out.len
|
||||
def_pos := g.definitions.len
|
||||
g.stmt(it.decl)
|
||||
fn_body := g.out.after(pos)
|
||||
g.out.go_back(fn_body.len)
|
||||
g.definitions.go_back(g.definitions.len - def_pos)
|
||||
g.definitions.write(fn_body)
|
||||
g.write('${it.decl.name}(it)')
|
||||
}
|
||||
else {
|
||||
g.expr(node.args[0].expr)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user