On Tue, 26 Sep 2023 10:21:06 GMT, Maurizio Cimadamore <mcimadam...@openjdk.org> 
wrote:

>> 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_.

@mcimadamore @lahodaj I attempted to do this split for non variables that do 
not allow underscore. I print the simple version of the error message. Is that 
what you meant Maurizio?

I also fixed the `UnderscoreAsIdent` adding the missing `--release 9`. It was 
the same omission as with other tests that @lahodaj pointed.

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

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

Reply via email to