From 12faf9fcfa4256d3a88e99a5819224c28ed2836a Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 10 Jun 2020 19:18:45 +0800 Subject: [PATCH] cgen: fix multiple array.map(anon_fn) calls --- vlib/builtin/array_test.v | 12 ++++++++++++ vlib/v/gen/fn.v | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index c252bbb42e..f412c58ba5 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -596,6 +596,18 @@ fn test_anon_fn_map() { assert [1,2,3].map(add_num) == [2,3,4] } +fn test_mutli_anon_fn_map() { + a := [1,2,3].map(fn (i int) int { + return i + 1 + }) + + b := [1,2,3].map(fn (i int) int { + return i + 2 + }) + assert a == [2,3,4] + assert b == [3,4,5] +} + fn test_anon_fn_arg_map() { a := [1,2,3].map(fn (i int) int { return i + 1 diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index 1d92891be7..86f382c29a 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -49,7 +49,6 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) { eprintln('INFO: compile with `v -live $g.pref.path `, if you want to use the [live] function ${it.name} .') } // - g.reset_tmp_count() if is_main { if g.pref.os == .windows { if g.is_gui_app() {