Incorrect exhaustivity computation

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 22
    • Affects Version/s: 21
    • Component/s: tools
    • b07

        Originally reported here:
        https://mail.openjdk.org/pipermail/compiler-dev/2023-July/023724.html

        Consider the following code:
        ```
        class Test22 {

          record Pair(I i1, I i2) {}

          sealed interface I {}

          record C() implements I {}

          record D() implements I {}

          void exhaustinvenessWithInterface(Pair pairI) {
            switch (pairI) {
              case Pair(D fst, C snd) -> {
              }
              case Pair(C fst, C snd) -> {
              }
              case Pair(C fst, I snd) -> {
              }
              case Pair(D fst, D snd) -> {
              }
            }
          }
        }
        ```

        The switch in this code should be exhaustive, but javac reports an exhaustivity error for this code:
        ```
        $ javac Test22.java
        Test22.java:13: error: the switch statement does not cover all possible input values
            switch (pairI) {
            ^
        1 error
        ```

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

                Created:
                Updated:
                Resolved: