RFR: 8294942: Compiler implementation for Record Patterns (Second Preview)
Jan Lahoda
jlahoda at openjdk.org
Sun Oct 30 18:52:33 UTC 2022
On Tue, 25 Oct 2022 09:52:39 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:
>> This is a partial implementation of [JEP 432: Record Patterns (Second Preview)](https://openjdk.org/jeps/432) and [JEP 433: Pattern Matching for switch (Fourth Preview)](https://openjdk.org/jeps/433). Namely, it implements:
>>
>> - removal of named record patterns
>> - (preview) type inference for type test and record patterns
>> - cleaner switch case specification (e.g. no combination of `null` constants and type test patterns)
>> - fixing exhaustiveness of certain switches
>>
>> The patch does not contain support for record patterns in enhanced for statements, that is [part of a separate pull request](https://github.com/openjdk/jdk/pull/10798).
>>
>> For more information on the changes please see:
>> - the JEPs: [JEP 432](https://openjdk.org/jeps/432) and [JEP 433](https://openjdk.org/jeps/433)
>> - the CSRs: [JEP 432 - JDK-8294944](https://bugs.openjdk.org/browse/JDK-8294944) and [JEP 433 - JDK-8294946](https://bugs.openjdk.org/browse/JDK-8294946)
>> - the current [specification draft](https://cr.openjdk.java.net/~gbierman/jep432%2b433/jep432+433-20221018/specs/patterns-switch-record-patterns-jls.html#jls-14.14.2) (note the draft does not yet include details on type inference)
>>
>> Any feedback is welcome.
>>
>> Thanks!
>
> test/langtools/tools/javac/patterns/NewCaseStructureTest.java line 283:
>
>> 281: case Integer i when i > 0 -> 0;
>> 282: case 0 -> 0;
>> 283: case Integer i -> 0;
>
> This case is not needed, right?
Well, omitting the unconditional case would make the switch non-exhaustive. While that would not be a blocker for a testcase that verifies that error are reported, I think it is cleaner to avoid unrelated errors in the source code.
-------------
PR: https://git.openjdk.org/jdk/pull/10814
More information about the compiler-dev
mailing list