1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix $if T.typ is Type { (#13135)

This commit is contained in:
yuyi 2022-01-11 22:25:16 +08:00 committed by GitHub
parent 10efe47f03
commit f3d8bbdf3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -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)

View File

@ -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'
}