1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix if expr with fn call result (#15702)

This commit is contained in:
yuyi 2022-09-09 03:39:49 +08:00 committed by GitHub
parent ec2ca38adb
commit 71f5f7f3a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -50,6 +50,11 @@ fn (mut g Gen) need_tmp_var_in_expr(expr ast.Expr) bool {
if expr.or_block.kind != .absent {
return true
}
for arg in expr.args {
if g.need_tmp_var_in_expr(arg.expr) {
return true
}
}
}
ast.CastExpr {
return g.need_tmp_var_in_expr(expr.expr)

View File

@ -0,0 +1,21 @@
fn foo() !int {
return 0
}
fn bar(n int) bool {
return true
}
fn is_ok(b bool) !bool {
return if b {
bar(foo()!)
} else {
true
}
}
fn test_if_expr_with_fn_call_result() {
ret := is_ok(true) or { false }
println(ret)
assert ret
}