RFR: 8274363: Transitively sealed classes not considered exhaustive in switches [v2]

Jan Lahoda jlahoda at openjdk.java.net
Fri Oct 1 06:57:57 UTC 2021


> Consider code like:
> 
> 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;
>         };
>     }
>     
> } 
> 
> 
> Note that `B1` covers `D1` and `B2` covers `D2`. So, `B1` and `B2` cover `C`, and hence `B1` and `B2` cover `A`.  To detect this, when looking for coverage of permitted types of `A`, we need to transitively look if any of the permitted type is covered.
> 
> The check uses the `DeferredCompletionFailureHandler`, because if don't want to fail the compilation on unresolvable permitted subclass. (In case the permitted subclass is covered by some other means, of course.)

Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:

  Fixing typo.

-------------

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/5717/files
  - new: https://git.openjdk.java.net/jdk/pull/5717/files/0a63b376..bf725e57

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=5717&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=5717&range=00-01

  Stats: 3 lines in 1 file changed: 0 ins; 0 del; 3 mod
  Patch: https://git.openjdk.java.net/jdk/pull/5717.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/5717/head:pull/5717

PR: https://git.openjdk.java.net/jdk/pull/5717


More information about the compiler-dev mailing list