Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFE error message for non-exhaustion of promoted-type-variable is misleading #54652

Open
lrhn opened this issue Jan 17, 2024 · 0 comments
Open
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-messages Poor/undesirable messaging in errors/warnings emitted by the CFE.

Comments

@lrhn
Copy link
Member

lrhn commented Jan 17, 2024

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.)

@lrhn lrhn added area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-messages Poor/undesirable messaging in errors/warnings emitted by the CFE. labels Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-messages Poor/undesirable messaging in errors/warnings emitted by the CFE.
Projects
None yet
Development

No branches or pull requests

1 participant