mirror of
https://github.com/vlang/v.git
synced 2025-09-09 07:15:50 -04:00
cgen: fix match with comptime if expr in branch (#19189)
This commit is contained in:
parent
2ce7109b30
commit
c3be85e87d
@ -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 {
|
||||
|
19
vlib/v/tests/match_with_comptime_if_expr_in_branch_test.v
Normal file
19
vlib/v/tests/match_with_comptime_if_expr_in_branch_test.v
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user