From b8935551f1583ab511edb9fe7709d972463c90bb Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 23 Sep 2021 13:50:37 +0800 Subject: [PATCH] cgen: fix nested array call (#11948) --- vlib/v/gen/c/array.v | 4 ++++ vlib/v/tests/array_nested_call_test.v | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 vlib/v/tests/array_nested_call_test.v diff --git a/vlib/v/gen/c/array.v b/vlib/v/gen/c/array.v index 79ac165cd9..b4b4de4055 100644 --- a/vlib/v/gen/c/array.v +++ b/vlib/v/gen/c/array.v @@ -167,6 +167,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.writeln('\t$inp_elem_type it = (($inp_elem_type*) ${tmp}_orig.data)[$i];') + g.stmt_path_pos << g.out.len mut is_embed_map_filter := false mut expr := node.args[0].expr match mut expr { @@ -349,6 +350,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('\t$elem_type_str it = (($elem_type_str*) ${tmp}_orig.data)[$i];') + g.stmt_path_pos << g.out.len mut is_embed_map_filter := false mut expr := node.args[0].expr match mut expr { @@ -631,6 +633,7 @@ fn (mut g Gen) gen_array_any(node ast.CallExpr) { i := g.new_tmp_var() g.writeln('for (int $i = 0; $i < ${tmp}_len; ++$i) {') g.writeln('\t$elem_type_str it = (($elem_type_str*) ${tmp}_orig.data)[$i];') + g.stmt_path_pos << g.out.len mut is_embed_map_filter := false mut expr := node.args[0].expr match mut expr { @@ -704,6 +707,7 @@ fn (mut g Gen) gen_array_all(node ast.CallExpr) { i := g.new_tmp_var() g.writeln('for (int $i = 0; $i < ${tmp}_len; ++$i) {') g.writeln('\t$elem_type_str it = (($elem_type_str*) ${tmp}_orig.data)[$i];') + g.stmt_path_pos << g.out.len mut is_embed_map_filter := false mut expr := node.args[0].expr match mut expr { diff --git a/vlib/v/tests/array_nested_call_test.v b/vlib/v/tests/array_nested_call_test.v new file mode 100644 index 0000000000..2a61b11ccf --- /dev/null +++ b/vlib/v/tests/array_nested_call_test.v @@ -0,0 +1,6 @@ +fn test_array_nested_call() { + arr := ['abc', 'def'] + all_is_letter := arr.all(it.bytes().all(it.is_letter())) + println(all_is_letter) + assert all_is_letter +}