Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgen: fix call_expr in branches and left_expr of call_expr with or_block(fix #20044) #20094

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions vlib/v/gen/c/if.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions vlib/v/tests/if_match_branches_with_call_expr_with_or_block_test.v
Original file line number Diff line number Diff line change
@@ -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'
}
Loading