Skip to content

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

Description

@stereotype441

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NNBDIssues related to NNBD Releaselegacy-area-front-endLegacy: Use area-dart-model instead.soundnesstype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions