diff --git a/vlib/v/gen/c/if.v b/vlib/v/gen/c/if.v index f5d1b68b71..6e807e1a60 100644 --- a/vlib/v/gen/c/if.v +++ b/vlib/v/gen/c/if.v @@ -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 { diff --git a/vlib/v/tests/match_with_comptime_if_expr_in_branch_test.v b/vlib/v/tests/match_with_comptime_if_expr_in_branch_test.v new file mode 100644 index 0000000000..9ce934c2ce --- /dev/null +++ b/vlib/v/tests/match_with_comptime_if_expr_in_branch_test.v @@ -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 +}