cgen: fix `$if T.typ is Type {` (#13135)
parent
10efe47f03
commit
f3d8bbdf3d
|
@ -375,7 +375,11 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) bool {
|
|||
}
|
||||
} else if left is ast.SelectorExpr {
|
||||
name = '${left.expr}.$left.field_name'
|
||||
exp_type = g.comptime_var_type_map[name]
|
||||
if left.gkind_field == .typ {
|
||||
exp_type = g.unwrap_generic(left.name_type)
|
||||
} else {
|
||||
exp_type = g.comptime_var_type_map[name]
|
||||
}
|
||||
} else if left is ast.TypeNode {
|
||||
// this is only allowed for generics currently, otherwise blocked by checker
|
||||
exp_type = g.unwrap_generic(left.typ)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
module main
|
||||
|
||||
fn write<T>(out T) string {
|
||||
$if T.typ is bool {
|
||||
println('FOO')
|
||||
return 'FOO'
|
||||
} $else $if T.typ !is bool {
|
||||
println('BAR')
|
||||
return 'BAR'
|
||||
}
|
||||
return 'EMPTY'
|
||||
}
|
||||
|
||||
fn test_comptime_if_expr_generic_typ_is_type() {
|
||||
mut val := false
|
||||
ret := write<bool>(val)
|
||||
assert ret == 'FOO'
|
||||
}
|
Loading…
Reference in New Issue