diff --git a/vlib/v/gen/c/if.v b/vlib/v/gen/c/if.v index 4305bdcc77..706037ab15 100644 --- a/vlib/v/gen/c/if.v +++ b/vlib/v/gen/c/if.v @@ -76,6 +76,7 @@ fn (mut g Gen) need_tmp_var_in_expr(expr ast.Expr) bool { return true } } + return expr.expected_arg_types.any(it.has_flag(.option)) } ast.CastExpr { return g.need_tmp_var_in_expr(expr.expr) diff --git a/vlib/v/tests/fns/call_option_param_test.v b/vlib/v/tests/fns/call_option_param_test.v new file mode 100644 index 0000000000..a239ba436f --- /dev/null +++ b/vlib/v/tests/fns/call_option_param_test.v @@ -0,0 +1,15 @@ +pub fn new_group(t ?Texts) Group { + return Group{} +} + +struct Group { +} + +struct Texts { +} + +fn test_main() { + a := 0 + _ := if a != 0 { new_group(Texts{}) } else { Group{} } + _ := if a != 0 { new_group(none) } else { Group{} } +}