RFR: 8262889: Compiler implementation for Record Patterns [v2]
Aggelos Biboudis
abimpoudis at openjdk.java.net
Fri May 6 14:32:54 UTC 2022
On Fri, 6 May 2022 14:09:24 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> 8262889: Compiler implementation for Record Patterns
>>
>> A first version of a patch that introduces record patterns into javac as a preview feature. For the specification, please see:
>> http://cr.openjdk.java.net/~gbierman/jep427+405/jep427+405-20220426/specs/patterns-switch-record-patterns-jls.html
>>
>> There are two notable tricky parts:
>> -in the parser, it was necessary to improve the `analyzePattern` method to handle nested/record patterns, while still keeping error recovery reasonable
>> -in the `TransPatterns`, the desugaring of the record patterns is very straightforward - effectivelly the record patterns are desugared into guards/conditions. This will likely be improved in some future version/preview
>>
>> `MatchException` has been extended to cover additional cases related to record patterns.
>
> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>
> Reflecting review feedback.
>From the JLS specdiff
> If the type R names a generic record class then it is a compile-time error if R is not a parameterized type.
The following snippet raises a `MatchException`. Shouldn't it be a compile-time error?
Box<String> r = new Box<>(null);
switch (r) {
case Box(String s):
System.out.println("match");
}
-------------
PR: https://git.openjdk.java.net/jdk/pull/8516
More information about the core-libs-dev
mailing list