Open
Description
If I do:
sealed class Sealed {}
class Sub extends Sealed {}
void test<T extends Object?>(T v) {
if (v is Sealed) {
switch (v) {
case _ when false: // Non-exhaustive switch.
}
}
}
I get an error (correctly) saying that the switch statement is not exhaustive, because the type T&Sealed
is always-exhaust.
The message is:
compile: lib/main.dart:6:13:
Error: The type 'T' is not exhaustively matched by the switch cases since it doesn't match 'Sub()'.
switch (v) {
^
The problem here is that the type that needs to be exhausted is Sealed
, not T
.
The analyzer, in comparison, reports:
error
line 6 • The type 'T & Sealed' is not exhaustively matched by the switch cases since it doesn't match 'Sub()'
That's technically correct, but arguably leaking the internal intersection type.
What the user knows it that they promoted to Sealed
, so they expect that they are working on Sealed
.
Still, it's better than T
.
(Found while testing extension types, but also applies to plain classes.)