Transitively sealed classes not considered exhaustive in switches

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 18
    • Affects Version/s: 17, 18
    • Component/s: tools
    • None
    • b18

      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.

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

              Created:
              Updated:
              Resolved: