Skip to content

Commit 6dcedae

Browse files
authored
cgen: fix if codegen when func parameter is option type (fix #24813) (#24816)
1 parent aadb0e9 commit 6dcedae

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

vlib/v/gen/c/if.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ fn (mut g Gen) need_tmp_var_in_expr(expr ast.Expr) bool {
7676
return true
7777
}
7878
}
79+
return expr.expected_arg_types.any(it.has_flag(.option))
7980
}
8081
ast.CastExpr {
8182
return g.need_tmp_var_in_expr(expr.expr)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pub fn new_group(t ?Texts) Group {
2+
return Group{}
3+
}
4+
5+
struct Group {
6+
}
7+
8+
struct Texts {
9+
}
10+
11+
fn test_main() {
12+
a := 0
13+
_ := if a != 0 { new_group(Texts{}) } else { Group{} }
14+
_ := if a != 0 { new_group(none) } else { Group{} }
15+
}

0 commit comments

Comments
 (0)