Integrated: 8327368: javac crash when computing exhaustiveness checks
Jan Lahoda
jlahoda at openjdk.org
Wed Jun 5 05:49:00 UTC 2024
On Mon, 3 Jun 2024 12:47:15 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Consider code like:
>
> package test;
>
> public class Test {
>
> sealed interface A permits T, U {}
>
> sealed interface B permits V, W {}
>
> static final class T implements A {}
>
> static final class U implements A {}
>
> static final class V implements B {}
>
> static final class W implements B {}
>
> final static record R(A a, B b) {}
>
> static int r(R r) {
> return switch (r) {
> case R(A a, V b) -> 1;
> case R(T a, B b) -> 2;
> case R(U a, W b) -> 3;
> };
> }
> }
>
>
> To properly evaluate exhaustiveness, we need to consider `R(T a, B b)` to act as `R(T a, W b)`, so that we can reduce `R(T a, W b)` and `R(U a, W b)` to `R(A a, W b)`. Which is then reduced together with `R(A a, V b)` to `R(A a, B b)` and consequently to just `R`.
>
> This was done under JDK-8325215, by expanding `B` into all possible subtypes, from which we can pick patterns for reduction. Eventually, that patch may need a more complete revamp, but the idea herein is just to prevent a `ClassCastException` when the type of the binding pattern is not a class-based type - typically, when it is a type variable. This patch uses the type variable's bounds as the based from which the permitted subtypes are computed.
This pull request has now been integrated.
Changeset: 1f094672
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/1f09467230971d6458918ec19ffeb259b8c028a3
Stats: 98 lines in 2 files changed: 91 ins; 0 del; 7 mod
8327368: javac crash when computing exhaustiveness checks
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/19523
More information about the compiler-dev
mailing list