mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix comptime "ident is type" (#18747)
This commit is contained in:
parent
ad1d5e7adb
commit
e01d973c27
@ -161,6 +161,13 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
|
||||
is_comptime_type_is_expr = true
|
||||
left_type := c.unwrap_generic(left.typ)
|
||||
skip_state = c.check_compatible_types(left_type, right as ast.TypeNode)
|
||||
} else if left is ast.Ident {
|
||||
is_comptime_type_is_expr = true
|
||||
mut checked_type := ast.void_type
|
||||
if var := left.scope.find_var(left.name) {
|
||||
checked_type = c.unwrap_generic(var.typ)
|
||||
}
|
||||
skip_state = c.check_compatible_types(checked_type, right as ast.TypeNode)
|
||||
}
|
||||
}
|
||||
} else if branch.cond.op in [.eq, .ne] {
|
||||
|
6
vlib/v/checker/tests/run/comptime_ident_is_type.run.out
Normal file
6
vlib/v/checker/tests/run/comptime_ident_is_type.run.out
Normal file
@ -0,0 +1,6 @@
|
||||
u64: true
|
||||
u64 array: 0
|
||||
other array: 1
|
||||
other array: 0
|
||||
other int: false
|
||||
unknown type
|
22
vlib/v/checker/tests/run/comptime_ident_is_type.vv
Normal file
22
vlib/v/checker/tests/run/comptime_ident_is_type.vv
Normal file
@ -0,0 +1,22 @@
|
||||
fn test[T](val T) {
|
||||
$if val is u64 {
|
||||
println('u64: ${val == u64(0)}')
|
||||
} $else $if val is []u64 {
|
||||
println('u64 array: ${val.len}')
|
||||
} $else $if val is $int {
|
||||
println('other int: ${val == 0}')
|
||||
} $else $if val is $array {
|
||||
println('other array: ${val.len}')
|
||||
} $else {
|
||||
println('unknown type')
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
test(u64(0))
|
||||
test([]u64{})
|
||||
test(['string'])
|
||||
test([]u32{})
|
||||
test(int(12))
|
||||
test('string')
|
||||
}
|
Loading…
Reference in New Issue
Block a user