Integrated: 8274363: Transitively sealed classes not considered exhaustive in switches
Jan Lahoda
jlahoda at openjdk.java.net
Fri Oct 1 08:57:45 UTC 2021
On Mon, 27 Sep 2021 18:05:26 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> 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.)
This pull request has now been integrated.
Changeset: 292d7bb1
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/292d7bb1d5d311b517b2cd6d0f6dc77e35b3f649
Stats: 72 lines in 2 files changed: 54 ins; 8 del; 10 mod
8274363: Transitively sealed classes not considered exhaustive in switches
Reviewed-by: vromero
-------------
PR: https://git.openjdk.java.net/jdk/pull/5717
More information about the compiler-dev
mailing list