RFR: 8327368: javac crash when computing exhaustiveness checks. [v2]

Vicente Romero vromero at openjdk.org
Tue Jun 4 13:19:17 UTC 2024


On Tue, 4 Jun 2024 12:24:59 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.
>
> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Must handle type variables using their bounds.

looks good

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

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/19523#pullrequestreview-2096366390


More information about the compiler-dev mailing list