Skip to content

Flow analysis detection of trivial exhaustiveness fails to understand [...]. #52017

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

Closed
stereotype441 opened this issue Apr 11, 2023 · 1 comment
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@stereotype441
Copy link
Member

(Filing this issue to accompany a cherry-pick request; the bulk of the work is tracked in dart-lang/language#2980).

As of the latest beta release (flutter/flutter#124515), list patterns containing a single rest pattern are not recognized by flow analysis as trivially exhaustive. As a result, a switch statement like the following will not be recognized by flow analysis as exhaustive:

f(List<Object> x) {
  String description;
  switch (x) {
    case [_]:
      description = 'one element';
    case [...]:
      description = 'some other number of elements';
  }
  print(description);
}

And thus there will be an error at the print statement claiming that description hasn't been definitely assigned.

Worse yet, if the user attempts to fix the problem by adding, e.g.:

    default:
      throw 'unreachable';

then the exhaustiveness checker will (correctly) report a warning that this default case is unreachable.

This affects all platforms, but only programs which use the patterns feature of Dart 3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

1 participant