RFR: 8294942: Compiler implementation for Record Patterns (Second Preview)
Aggelos Biboudis
abimpoudis at openjdk.org
Sun Oct 30 18:52:33 UTC 2022
On Fri, 21 Oct 2022 11:56:50 GMT, Jan Lahoda <jlahoda 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!
Some minor comments.
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java line 656:
> 654: }
> 655:
> 656: public Type instantiatePatternType(DiagnosticPosition pos, Type expressionType, TypeSymbol patternTypeSymbol) {
`pos` seems unused so far.
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?
test/langtools/tools/javac/patterns/NewCaseStructureTest.java line 299:
> 297: case E e when e == E.A -> 0;
> 298: case B -> 0;
> 299: case E e -> 0;
Similarly.
test/langtools/tools/javac/patterns/NewCaseStructureTest.java line 316:
> 314: case String s when s.isEmpty() -> 0;
> 315: case "a" -> 0;
> 316: case String s -> 0;
Similarly.
test/langtools/tools/javac/patterns/NewCaseStructureTest.java line 348:
> 346: default -> 0;
> 347: case (Integer i) when i > 0 -> 0;
> 348: case (Integer i) when i > 0 -> 0;
Similarly.
test/langtools/tools/javac/patterns/NewCaseStructureTest.java line 361:
> 359: private int test(Integer o) {
> 360: return switch (o) {
> 361: case (Integer i) when i > 0 -> 0;
Similarly.
-------------
PR: https://git.openjdk.org/jdk/pull/10814
More information about the compiler-dev
mailing list