RFR: 8302344: Compiler Implementation for Unnamed patterns and variables (Preview) [v26]

Maurizio Cimadamore mcimadamore at openjdk.org
Wed May 17 23:42:04 UTC 2023

On Wed, 17 May 2023 14:23:37 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:

>> This PR implements [JEP 443](https://openjdk.org/jeps/443), the preview feature for Unnamed Patterns and Variables in Java.
>> Draft Spec: https://cr.openjdk.org/~abimpoudis/unnamed/latest/
> Aggelos Biboudis has updated the pull request incrementally with one additional commit since the last revision:
>   Simplify `LambdaClassifier`
>   Co-authored-by: Maurizio Cimadamore <maurizio.cimadamore at oracle.com>

src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 2071:

> 2069:         /**
> 2070:          * analyzeParens() has already classified the lambda as EXPLICIT_LAMBDA, due to
> 2071:          * two consecutive identifiers. adding an erroneous parameter (one that

Shouldn't the second sentence say something more like:

Because of that (<explicit lambda>), the parser will always attempt to parse a type, followed by a name.
If the lambda contains an illegal mix of implicit and explicit parameters, it is possible for the parser to see a `,` when expecting a name, in which case the variable is created with an erroneous name.
The logic below makes sure that the lambda parameters are all declared with either an explicit type (e.g. `String x`), or with an inferred type (using `var x`).
Any other combination is rejected.


PR Review Comment: https://git.openjdk.org/jdk/pull/13528#discussion_r1197166447

More information about the compiler-dev mailing list