RFR: 8302344: Compiler Implementation for Unnamed patterns and variables (Preview) [v12]
Aggelos Biboudis
abimpoudis at openjdk.org
Thu May 4 18:23:24 UTC 2023
On Thu, 4 May 2023 17:48:31 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 3591:
>>
>>> 3589: }
>>> 3590: }
>>> 3591: result = toP(F.at(pos).VarDef(mods, name, type, init, declaredUsingVar));
>>
>> I think this should check whether name is underscore (and feature is enabled) and, if that's the case, replace the name with an empty name, so that the rest of the compiler is already correct.
>>
>> Also, related, no matter what, I think javac's Pretty class should be updated to render variables with empty name as "_" when the tree is turned back into source.
>
> yep I agree with this, the parser should set the right name as soon as it sees a `_`
We could indeed if we wanted to store `empty` everywhere. However, after some off-list discussions I updated the CSR (and the code) to include `empty` as the name at the symbol-level (for consistency with javax model) and `_` at the Tree API-level for its version of a name. This is the rationale behind what you see in Attr (for patterns) and member enter for all other cases. @jddarcy what do you think?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13528#discussion_r1185358285
More information about the compiler-dev
mailing list