diff --git a/vlib/v/gen/c/if.v b/vlib/v/gen/c/if.v index 2d485e60874252..fe7cc18f7d6f78 100644 --- a/vlib/v/gen/c/if.v +++ b/vlib/v/gen/c/if.v @@ -79,6 +79,9 @@ fn (mut g Gen) need_tmp_var_in_expr(expr ast.Expr) bool { if expr.or_block.kind != .absent { return true } + if g.need_tmp_var_in_expr(expr.left) { + return true + } for arg in expr.args { if g.need_tmp_var_in_expr(arg.expr) { return true diff --git a/vlib/v/tests/if_match_branches_with_call_expr_with_or_block_test.v b/vlib/v/tests/if_match_branches_with_call_expr_with_or_block_test.v new file mode 100644 index 00000000000000..50e2bcb8ac4f81 --- /dev/null +++ b/vlib/v/tests/if_match_branches_with_call_expr_with_or_block_test.v @@ -0,0 +1,26 @@ +fn foo() !string { + return 'abc' +} + +// exists call_expr in the if-else branches and the left_expr of call_expr with or_block +fn test_if() { + res := if false { + '' + } else { + foo() or { panic('error') }.trim('') + } + assert res == 'abc' +} + +// exists call_expr in the match branches and the left_expr of call_expr with or_block +fn test_match() { + res := match false { + true { + '' + } + else { + foo() or { panic('error') }.trim('') + } + } + assert res == 'abc' +}