From 84fc587ec23626d7705b50ffe036ec134d73dafc Mon Sep 17 00:00:00 2001 From: Steve Phillips Date: Tue, 5 May 2020 01:29:23 -0700 Subject: [PATCH] cgen: use a temp var in map() --- vlib/v/gen/cgen.v | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 4768c96e74..bf3af6458c 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2576,10 +2576,11 @@ fn (mut g Gen) gen_map(node ast.CallExpr) { g.expr(node.left) g.writeln('.len;') g.writeln('$ret_typ $tmp = __new_array(0, ${tmp}_len, sizeof($ret_elem_type));') - g.writeln('for (int i = 0; i < ${tmp}_len; i++) {') + 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*) ') g.expr(node.left) - g.writeln('.data)[i];') + g.writeln('.data)[$i];') g.write('\t$ret_elem_type ti = ') g.expr(node.args[0].expr) // the first arg is the filter condition g.writeln(';')