Closed
Description
Hello!
As we know, void
is the type that indicates that a value shouldn't be used.
For example:
void a = 10;
print(a);
This code won't be compiled because of error
Error: This expression has type 'void' and can't be used.
print(a);
But, if we will use void a
with a generic function, then this will compile and even work.
void f<T>(T a) {
print(T);
print(a.runtimeType);
print(a);
}
void main() {
void a = 10;
f(a);
}
This code will print us this output:
void
int
10
So, as we can see, generic type is void, but this works fine.
But, if we will change generic in the function to the <T extends Object>
or will use dynamic a
instead of generic, then we will get expected type errors.
Also, if we will use <T extends Object?>
, then it also compile fine.
So, is this an bug and compiler should know that void should not be used as a generic, or this is expected behaviour?