RFR: 8315532: Compiler Implementation for Unnamed Variables and Patterns

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Sep 26 10:24:21 UTC 2023


On Mon, 25 Sep 2023 16:59:30 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> This PR finalizes the feature of unnamed variables and patterns.
>> 
>> ---------
>> ### Progress
>> - [ ] Change must be properly reviewed (1 review required, with at least 1 [Reviewer](https://openjdk.org/bylaws#reviewer))
>> - [x] Change must not contain extraneous whitespace
>> - [x] Commit message must refer to an issue
>> - [ ] Change requires CSR request [JDK-8315851](https://bugs.openjdk.org/browse/JDK-8315851) to be approved
>> 
>> 
>> 
>> ### Reviewing
>> <details><summary>Using <code>git</code></summary>
>> 
>> Checkout this PR locally: \
>> `$ git fetch https://git.openjdk.org/jdk.git pull/15649/head:pull/15649` \
>> `$ git checkout pull/15649`
>> 
>> Update a local copy of the PR: \
>> `$ git checkout pull/15649` \
>> `$ git pull https://git.openjdk.org/jdk.git pull/15649/head`
>> 
>> </details>
>> <details><summary>Using Skara CLI tools</summary>
>> 
>> Checkout this PR locally: \
>> `$ git pr checkout 15649`
>> 
>> View PR using the GUI difftool: \
>> `$ git pr show -t 15649`
>> 
>> </details>
>> <details><summary>Using diff file</summary>
>> 
>> Download this PR as a diff file: \
>> <a href="https://git.openjdk.org/jdk/pull/15649.diff">https://git.openjdk.org/jdk/pull/15649.diff</a>
>> 
>> </details>
>> 
>> 
>> ### Webrev
>> [Link to Webrev Comment](https://git.openjdk.org/jdk/pull/15649#issuecomment-1733906010)
>
> test/langtools/tools/javac/lambda/IdentifierTest9.out line 33:
> 
>> 31: IdentifierTest.java:152:17: compiler.err.use.of.underscore.not.allowed
>> 32: IdentifierTest.java:158:16: compiler.err.use.of.underscore.not.allowed.with.brackets
>> 33: IdentifierTest.java:160:25: compiler.err.use.of.underscore.not.allowed
> 
> Note the errors are like:
> 
> /home/jlahoda/src/jdk/jdk2/test/langtools/tools/javac/lambda/IdentifierTest.java:160: error: as of release 21, the underscore keyword '_' is only allowed to declare
>         for(String _s : _ ) {
>                         ^
>   unnamed patterns, local variables, exception parameters or lambda parameters
> 
> 
> At least the release version should be updated, but to not let the message to be broken into two lines like this. Maybe produce a top-level diagnostic along the line of "underscore not allowed here" with sub-diagnostic with the details (which then can (maybe?) span multiple lines).
> 
> Also, the wording sounds to me like if there was a restriction in JDK 22, while underscore is actually permitted on more places than before.
> 
> So, maybe something like:
> 
> 
> underscore not allowed here
> as of release 9, ''_'' is a keyword, and may not be used as an identifier
> as of release 21, ''_'' can be used as a name in the declaration of unnamed patterns, local variables, exception parameters or lambda parameters
> 
> ?
> Just an idea.

I agree. Also, this is not helped by the fact that in this particular message, the `_` does not appear in a variable declaration. Maybe we should use two distinct messages for when `_` is found as an "expression" (e.g. an identifier) and when it is used as a declaration _name_.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15649#discussion_r1336987040


More information about the compiler-dev mailing list