From 43adbf4b66ccf85add093565a34df35b8c26ce30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Mon, 4 Jan 2021 01:04:53 +0100 Subject: [PATCH] cgen: fix filter in map (#7844) --- vlib/v/gen/array.v | 2 ++ vlib/v/tests/filter_in_map_test.v | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 vlib/v/tests/filter_in_map_test.v diff --git a/vlib/v/gen/array.v b/vlib/v/gen/array.v index 08f1986509..1510570e7f 100644 --- a/vlib/v/gen/array.v +++ b/vlib/v/gen/array.v @@ -149,6 +149,7 @@ fn (mut g Gen) gen_array_map(node ast.CallExpr) { i := g.new_tmp_var() g.writeln('for (int $i = 0; $i < ${tmp}_len; ++$i) {') g.write('\t$inp_elem_type it = (($inp_elem_type*) ${tmp}_orig.data)[$i];') + g.stmt_path_pos << g.out.len g.write('\t$ret_elem_type ti = ') expr := node.args[0].expr match expr { @@ -302,6 +303,7 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) { i := g.new_tmp_var() g.writeln('for (int $i = 0; $i < ${tmp}_len; ++$i) {') g.writeln(' $elem_type_str it = (($elem_type_str*) ${tmp}_orig.data)[$i];') + g.stmt_path_pos << g.out.len g.write('if (') expr := node.args[0].expr match expr { diff --git a/vlib/v/tests/filter_in_map_test.v b/vlib/v/tests/filter_in_map_test.v new file mode 100644 index 0000000000..7eb02baa17 --- /dev/null +++ b/vlib/v/tests/filter_in_map_test.v @@ -0,0 +1,5 @@ +fn filter_in_map_test() { + x := [['']] + y := x.map(it.filter(it != '')) + assert y[0].len == 0 +} \ No newline at end of file