RFR: 8300543 Compiler Implementation for Pattern Matching for switch [v2]

Jan Lahoda jlahoda at openjdk.org
Thu Apr 20 17:11:04 UTC 2023


On Tue, 18 Apr 2023 14:17:02 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> I've also found an infinite loop with this:
>> 
>> 
>> class Test {
>>     sealed interface I0 permits I1, I2 { }
>>     sealed interface I00 permits I1, I2 { }
>> 
>>     sealed interface I1 extends I0, I00 permits B, C { }
>>     sealed interface I2 extends I0, I00 permits B, C { }
>> 
>>     static final class B implements I1, I2 { }
>>     static final class C implements I1, I2 { }
>> 
>>     int test(Object o) {
>>         return switch (o) {
>>             case B c -> 2;
>>             case C d -> 3;
>>         };
>>     }
>> }
>
>> I've also found an infinite loop with this:
> 
> I believe this has to do with the fact that the list of pattern is not a set - so we can end up adding the same pattern descriptions over and over.

Thanks for the testcase!

I've tried to fix this by (avoiding to add redundant binding patterns):
https://github.com/openjdk/jdk/pull/13074/commits/7e6ed619d89784c49a96984c0f74176a9e0bcf63

Sets might be a good move eventually, but so far it seemed to hide problems, which quite probably needed to be solved anyway, so I kept the list impl for now.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13074#discussion_r1172874262


More information about the core-libs-dev mailing list