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:
parent
ec2ca38adb
commit
71f5f7f3a7
@ -50,6 +50,11 @@ fn (mut g Gen) need_tmp_var_in_expr(expr ast.Expr) bool {
|
|||||||
if expr.or_block.kind != .absent {
|
if expr.or_block.kind != .absent {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
for arg in expr.args {
|
||||||
|
if g.need_tmp_var_in_expr(arg.expr) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ast.CastExpr {
|
ast.CastExpr {
|
||||||
return g.need_tmp_var_in_expr(expr.expr)
|
return g.need_tmp_var_in_expr(expr.expr)
|
||||||
|
21
vlib/v/tests/if_expr_with_fn_call_result_test.v
Normal file
21
vlib/v/tests/if_expr_with_fn_call_result_test.v
Normal 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user