Skip to content

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

Closed
@stereotype441

Description

@stereotype441

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions