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

checker: fix comptime if generic value shift (#15471)

This commit is contained in:
yuyi 2022-08-20 13:15:52 +08:00 committed by GitHub
parent 46f32fc10c
commit 6062708c60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -401,7 +401,9 @@ pub fn (mut c Checker) check_matching_function_symbols(got_type_sym &ast.TypeSym
return true return true
} }
fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type ast.Type, right_type ast.Type) ast.Type { fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type_ ast.Type, right_type_ ast.Type) ast.Type {
left_type := c.unwrap_generic(left_type_)
right_type := c.unwrap_generic(right_type_)
if !left_type.is_int() { if !left_type.is_int() {
left_sym := c.table.sym(left_type) left_sym := c.table.sym(left_type)
// maybe it's an int alias? TODO move this to is_int()? // maybe it's an int alias? TODO move this to is_int()?

View File

@ -0,0 +1,13 @@
fn generic<T>(val T) T {
$if T is u64 {
println(val << 1)
return val << 1
}
return val
}
fn test_comptime_if_generic_shift() {
ret := generic(u64(2))
println(ret)
assert ret == 4
}