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 exhuastiveness checker confused by object patterns with private getter names #52041

Closed
stereotype441 opened this issue Apr 14, 2023 · 1 comment
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. P1 A high priority bug; for example, a single project is unusable or has many test failures

Comments

@stereotype441
Copy link
Member

The following program is accepted by the analyzer but rejected by the CFE:

sealed class B {}

class C extends B {
  final int _i;

  C(this._i);
}

f(B b) {
  switch (b) {
    case C(:var _i):
      print('C($_i)');
  }
}

main() {
  f(C(0));
}

The CFE's error message is:

../../tmp/proj/test.dart:10:11: Error: The type 'B' is not exhaustively matched by the switch cases since it doesn't match 'C(_i: Object())'.
 - 'B' is from '../../tmp/proj/test.dart'.
Try adding a default case or cases that match 'C(_i: Object())'.
  switch (b) {
          ^

I believe the analyzer is correct. The switch should be considered exhaustive.

I suspect the problem has to do with the fact that the getter _i is private. If I rename it to i, both the analyzer and the CFE accept the program.

This is probably a severe enough issue that we'll want to cherry-pick a fix to the stable branch.
CC @johnniwinther

@stereotype441 stereotype441 added P1 A high priority bug; for example, a single project is unusable or has many test failures area-front-end Use area-front-end for front end / CFE / kernel format related issues. labels Apr 14, 2023
@leafpetersen
Copy link
Member

This is probably worth considering for a cherry pick if we can get it fixed promptly.

@johnniwinther johnniwinther self-assigned this Apr 24, 2023
copybara-service bot pushed a commit that referenced this issue May 15, 2023
… checking

Closes #52041

Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/297462
Change-Id: I2bc2fc8fb38b30eb5e9c6e639c2603a5508dfec1
Fixes: #52254
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302845
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
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. P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

3 participants