Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8309336

Incorrect switch in enum not reported properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 21
    • None
    • tools
    • None
    • b26

      Consider code like:
      ```
      public class QualEnum {
          private void test(E e) {
              switch (e) {
                  case ea -> {}
                  default -> {}
              }
          }
          static final E ea = E.A;
          enum E {A}
      }
      ```

      This should fail to compile with a proper compile-time error, but it crashes javac:
      ```
      java.lang.AssertionError
      at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
      at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
      at jdk.compiler/com.sun.tools.javac.comp.Lower$CompileTimeEnumMapping.caseValue(Lower.java:505)
      at jdk.compiler/com.sun.tools.javac.comp.Lower.visitEnumSwitch(Lower.java:3866)
      ...
      ```

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: