cgen: fix match with comptime if expr in branch (#19189)

This commit is contained in:
yuyi 2023-08-21 15:46:40 +08:00 committed by GitHub
parent 2ce7109b30
commit c3be85e87d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -7,7 +7,8 @@ import v.ast
fn (mut g Gen) need_tmp_var_in_if(node ast.IfExpr) bool {
if node.is_expr && g.inside_ternary == 0 {
if g.is_autofree || node.typ.has_flag(.option) || node.typ.has_flag(.result) {
if g.is_autofree || node.typ.has_flag(.option) || node.typ.has_flag(.result)
|| node.is_comptime {
return true
}
for branch in node.branches {

View File

@ -0,0 +1,19 @@
fn test_match_with_comptime_if_expr_in_branch() {
x := match 'green' {
'red' {
'color is red'
}
'green' {
$if windows {
'color is green windows'
} $else {
'color is green unix'
}
}
else {
'nothing to say'
}
}
println(x)
assert true
}