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

Transitively sealed classes not considered exhaustive in switches

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • P3
    • Resolution: Fixed
    • 17, 18
    • 18
    • tools
    • None
    • 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

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

              Dates

                Created:
                Updated:
                Resolved: