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

Transitively sealed classes not considered exhaustive in switches

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 18
    • 17, 18
    • 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.

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

              Created:
              Updated:
              Resolved: