Skip to content

Exhaustiveness check should be able to prefer API instead of non-API witnesses #52682

Open
@scheglov

Description

@scheglov

See https://dart-review.googlesource.com/c/sdk/+/308520 for the initial question.

With this CL, if we write switch like this:

void f(TypedLiteral node) {
  switch (node) {
  }
}

...and use "Add missing case" twice, it does end up with using implementation classes.

void f(TypedLiteral node) {
  switch (node) {
    case ListLiteralImpl():
      // TODO: Handle this case.
    case SetOrMapLiteralImpl():
      // TODO: Handle this case.
  }
}

It does not have to, and this API version works as well.

void f(TypedLiteral node) {
  switch (node) {
    case ListLiteral():
      // TODO: Handle this case.
    case SetOrMapLiteral():
      // TODO: Handle this case.
  }
}

So, here we might have a tooling issue. Either CFE should be enhanced to prefer reporting witnesses that are available in the target code, maybe some filtering, etc. Or the quick fix should climb up. Ideologically, I think it should be CFE. Or the analyzer in a way how it feeds data into CFE, e.g. never return non-API classes that the target package should not use. Not different than how code completion will not suggest non-API classes from other packages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.dart-model-language-patternsIssues with analyzer's support for the patterns language featuremodel-exhaustivenessImplementation of exhaustiveness checkingtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions