Open
Description
Consider the following sealed hierarchy:
sealed class Base<A> {}
sealed class Mid<A, B> extends Base<A> {}
final class Final<A, B> extends Mid<A, B> {}
We can then use it with pattern matching like so:
void main() {
Base<int> base = Final<int, Object?>();
switch (base) {
case Final<int, Object?>():
print('42');
}
}
The problem is, this switch
is considered non-exhaustive.
To have the compiler consider the switch as exhaustive, we incorrectly have to change Final<int, Object?>()
into Final<Object?, Object?>()
.
This is incorrect, because given Base<int>
, it is guaranteed that all instances will implement Final<int, ...>
Removing the intermediary Mid
class fixes the issue, so it probably has to do with the added level of indirection.