mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: allow ~T(0)
where T is int
(#17886)
This commit is contained in:
parent
39b3a0ca17
commit
902d0dc93d
@ -3843,7 +3843,8 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
|
||||
c.error('cannot dereference to void', node.pos)
|
||||
}
|
||||
}
|
||||
if node.op == .bit_not && !right_type.is_int() && !c.pref.translated && !c.file.is_translated {
|
||||
if node.op == .bit_not && !c.unwrap_generic(right_type).is_int() && !c.pref.translated
|
||||
&& !c.file.is_translated {
|
||||
c.type_error_for_operator('~', 'integer', right_sym.name, node.pos)
|
||||
}
|
||||
if node.op == .not && right_type != ast.bool_type_idx && !c.pref.translated
|
||||
|
@ -5,6 +5,11 @@ fn simple[T](p T) T {
|
||||
return p
|
||||
}
|
||||
|
||||
fn bit_not_op_generic[T]() T {
|
||||
x := ~T(0)
|
||||
return x
|
||||
}
|
||||
|
||||
fn test_infer() {
|
||||
call(3)
|
||||
i := 4
|
||||
@ -17,6 +22,8 @@ fn test_explicit_calls_should_also_work() {
|
||||
assert true
|
||||
simple[int](5)
|
||||
assert true
|
||||
x := bit_not_op_generic[u32]()
|
||||
assert x == u32(4294967295)
|
||||
}
|
||||
|
||||
fn get_type_name[T](x T) string {
|
||||
|
Loading…
Reference in New Issue
Block a user