cgen: fix if codegen when func parameter is option type (fix #24813) (#24816)

This commit is contained in:
Felipe Pena 2025-06-30 16:04:15 -03:00 committed by GitHub
parent aadb0e9435
commit 6dcedae784
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -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)

View File

@ -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{} }
}