dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.25k stars 1.58k forks source link

NNBD. Error instead of warning for enum and switch with not all cases #40395

Closed sgrekhov closed 4 years ago

sgrekhov commented 4 years ago

NNBD specification reads

If T is an enum type, it is a warning if the switch does not handle all enum cases, either explicitly or via a default.

In fact, it is an error instead of warning

enum E {
  one,
  two,
  three
}
main() {
  E e = E.three;
  switch (e) { // error - Missing case clause for 'three'
    case E.one:
      true;
      break;
    case E.two:
      false;
      break;
  }
}

Tested on dartanalyzer version 2.8.0-dev.6.0

scheglov commented 4 years ago

This was fixed as https://github.com/dart-lang/sdk/issues/40547