RFR: 8294942: Compiler implementation for Record Patterns (Second Preview) [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Nov 7 09:08:22 UTC 2022


On Mon, 7 Nov 2022 08:49:35 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](http://cr.openjdk.java.net/~gbierman/jep432%2b433/jep432%2b433-20221028/specs/patterns-switch-record-patterns-jls.html)
>> 
>> Current total specdiff for both this PR and [the enhanced for PR](https://github.com/openjdk/jdk/pull/10798) is [here](http://cr.openjdk.java.net/~jlahoda/8294945/specdiff.preliminary.00/overview-summary.html).
>> 
>> Any feedback is welcome.
>> 
>> Thanks!
>
> Jan Lahoda has updated the pull request incrementally with three additional commits since the last revision:
> 
>  - Better tests for inference with recursive bounds, and related fixes.
>  - Adding a kind to InstanceOfTree, as suggested.
>  - Reflecting review feedback.

Looks good - left some minor comments

src/jdk.compiler/share/classes/com/sun/source/tree/InstanceOfTree.java line 97:

> 95: 
> 96:     /**
> 97:      * Returns the type of this instanceof expression.

Suggestion:

     * Returns the kind of this instanceof expression.

src/jdk.compiler/share/classes/com/sun/source/tree/InstanceOfTree.java line 99:

> 97:      * Returns the type of this instanceof expression.
> 98:      *
> 99:      * @return the type of this instanceof expression

Suggestion:

     * @return the kind of this instanceof expression

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java line 717:

> 715:             } else {
> 716:                 List<Type> upperBounds = undet.getBounds(InferenceBound.UPPER);
> 717:                 Type bound;

Maybe we should call this `upper`, for uniformity

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

Marked as reviewed by mcimadamore (Reviewer).

PR: https://git.openjdk.org/jdk/pull/10814


More information about the compiler-dev mailing list