diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 8b59eddd06..31b5c0acc7 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -4522,7 +4522,10 @@ fn (mut g Gen) if_expr(node ast.IfExpr) { if needs_tmp_var { g.stmts_with_tmp_var(branch.stmts, tmp) } else { + // restore if_expr stmt header pos + stmt_pos := g.nth_stmt_pos(0) g.stmts(branch.stmts) + g.stmt_path_pos << stmt_pos } } g.writeln('}') diff --git a/vlib/v/tests/if_expression_test.v b/vlib/v/tests/if_expression_test.v index 7603c3dc32..3955a4e6a4 100644 --- a/vlib/v/tests/if_expression_test.v +++ b/vlib/v/tests/if_expression_test.v @@ -199,3 +199,17 @@ fn min(a T, b T) T { fn test_if_expr_with_fn_generic() { assert min(42, 13) == 13 } + +fn test_if_expr_with_complex_array_methods() { + mut ret := []string{} + entries := ['a', 'b', 'c'] + + if false { + ret = entries.map(it.capitalize()) + } else if entries.any(it == 'a') { + ret = entries.map(it) + } + + println(ret) + assert ret == ['a', 'b', 'c'] +}