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

Transitively sealed classes not considered exhaustive in switches

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 17, 18
    • Fix Version/s: 18
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b18

      Description

      As reported here:

      https://mail.openjdk.java.net/pipermail/amber-spec-experts/2021-July/003049.html

      Consider this case:
      ---
      public class SwitchCoverage {
          sealed interface A {}
          sealed interface B1 extends A {}
          sealed interface B2 extends A {}
          sealed interface C extends A {}
          final class D1 implements B1, C {}
          final class D2 implements B2, C {}
          
          void test(A arg) {
              int i = switch (arg) {
                  case B1 b1 -> 1;
                  case B2 b2 -> 2;
              };
          }
          
      }
      ---

      The case should be considered exhaustive, but it is not.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: