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

Incorrect exhaustivity computation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 22
    • 21
    • tools
    • b07

    Backports

      Description

        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
        ```

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: