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

NNBD. 'switch' error for nullable enum type #40394

Closed
sgrekhov opened this issue Jan 30, 2020 · 1 comment
Closed

NNBD. 'switch' error for nullable enum type #40394

sgrekhov opened this issue Jan 30, 2020 · 1 comment
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. NNBD Issues related to NNBD Release type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sgrekhov
Copy link
Contributor

Consider the following code

enum E {
  one,
  two,
  three
}

main() {
  E? e = E.three;
  switch (e) { // error - Type 'E?' of the switch expression isn't assignable to the type 'E' of case expressions
    case E.one:
      true;
      break;
    case E.two:
      false;
      break;
    default:
      42;
  }
}

Tested on dartanalyzer version 2.8.0-dev.6.0

@lrhn lrhn added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. NNBD Issues related to NNBD Release type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jan 30, 2020
@lrhn
Copy link
Member

lrhn commented Jan 30, 2020

Error suggests what is wrong.
It's the run-time type of the case expression constants which must be subtypes of the static type of e, not the other way around.

@scheglov scheglov self-assigned this Feb 7, 2020
dart-bot pushed a commit that referenced this issue Feb 7, 2020
No changes to enum validation yet.

Bug: #40394
Change-Id: I2cca426b5b59d18a6244622f84884a3747a07190
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134888
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
@scheglov scheglov closed this as completed Feb 8, 2020
dart-bot pushed a commit that referenced this issue Feb 8, 2020
Bug: #40394
Change-Id: I9e8112ead97d5ecaccc167b2378112cefa391bcc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134874
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. NNBD Issues related to NNBD Release type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants