Skip to content

CFE fails to account for null when checking whether a switch statement as exhaustive #43348

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 Sep 7, 2020 · 2 comments
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. NNBD Issues related to NNBD Release soundness type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@stereotype441
Copy link
Member

The following program is accepted by the CFE:

enum A {
  b, c
}

int f(A? a) {
  switch (a) {
    case A.b:
    case A.c:
    return 0;
  }
}

main() {
  f(A.b);
}

It should be rejected, since the switch statement is non-exhaustive (it doesn't handle null), and therefore null might be returned from f, in violation of its static type. This is a soundness issue.

@stereotype441
Copy link
Member Author

See also dart-lang/language#1143 (comment)

@franklinyow
Copy link
Contributor

@leafpetersen Can you triage this? Thx

@leafpetersen leafpetersen added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) NNBD Issues related to NNBD Release labels Sep 10, 2020
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. NNBD Issues related to NNBD Release soundness type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants