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

Incorrect not exhaustive switch error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 23
    • 21, 22, 23
    • tools
    • b12

      Consider code like:
      ---
      package test;

      public class Test {

          sealed interface A permits T, U {}

          sealed interface B permits V, W {}

          static final class T implements A {}

          static final class U implements A {}

          static final class V implements B {}

          static final class W implements B {}

          final static record R(A a, B b) {}

          static int r(R r) {
              return switch (r) {
                  case R(A a, V b) -> 1;
                  case R(T a, B b) -> 2;
                  case R(U a, W b) -> 3;
              };
          }
      }
      ---

      This should be exhaustive, but an error is reported:
      ---
      $ javac /tmp/Test.java
      /tmp/Test.java:20: error: the switch expression does not cover all possible input values
              return switch (r) {
                     ^
      1 error
      ---

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

              Created:
              Updated:
              Resolved: