Skip to content

Analyzer: case labels need some constraints checked #3528

Closed
@DartBot

Description

@DartBot

This issue was originally filed by [email protected]


main() {
  var x = 1;
  try {
    switch(x) {
      case 0:
      case 2:
      case "false": // should error here
    }
  } catch(var e) {}
}

Given a switch statement of the form
 * switch (e) { label11 … label1j1 case e1: s1 … labeln1 ..labelnjn case en: sn default: sn+1}
 * or the form switch (e) { label11 … label1j1 case e1: s1 … labeln1 ..labelnjn case en: sn},
 * it is a compile-time error if the expressions ek are not compile-time constants,
 * of type int or String, for all 1 <= k <= n.

See tests:
  co19/Language/11_Statements/08_Switch_A05_t01.dart
  co19/Language/11_Statements/08_Switch_A05_t02.dart
  co19/Language/11_Statements/08_Switch_A06_t01.dart
  co19/Language/11_Statements/08_Switch_A06_t02.dart
   ... and friends

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions