diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index f5f632ddfb..cfef4a0357 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -5332,10 +5332,11 @@ fn (mut g Gen) if_expr(node ast.IfExpr) { is_auto_heap = v.is_auto_heap } } + left_var_name := c_name(branch.cond.var_name) if is_auto_heap { - g.writeln('\t$base_type* $branch.cond.var_name = HEAP($base_type, *($base_type*)${var_name}.data);') + g.writeln('\t$base_type* $left_var_name = HEAP($base_type, *($base_type*)${var_name}.data);') } else { - g.writeln('\t$base_type $branch.cond.var_name = *($base_type*)${var_name}.data;') + g.writeln('\t$base_type $left_var_name = *($base_type*)${var_name}.data;') } } } diff --git a/vlib/v/tests/reserved_keywords_if_guard_test.v b/vlib/v/tests/reserved_keywords_if_guard_test.v new file mode 100644 index 0000000000..b1ff0fd7b6 --- /dev/null +++ b/vlib/v/tests/reserved_keywords_if_guard_test.v @@ -0,0 +1,11 @@ +fn array_n_opt(n int) ?[]int { + return if n >= 0 { []int{len: n} } else { none } +} + +fn test_reserved_keyword_of_if_guard() { + if array := array_n_opt(2) { + assert array.len == 2 + } else { + assert false + } +}