RFR: 8294943: Implement record patterns in enhanced for [v15]
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Nov 24 17:14:30 UTC 2022
On Thu, 24 Nov 2022 13:43:02 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> Aggelos Biboudis has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Add @enablePreview
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 3016:
>
>> 3014: return ForInitResult.LocalVarDecl;
>> 3015: }
>> 3016: else if(peekToken(lookahead, COLON)) {
>
> Does this logic works with nested record patterns? You don't seem to "count" the parenthesis... I do see tests with it though...
This is an example I found where classification goes wrong:
for (m(a ? b() : c) ; ;) {}
This used to parse correctly, but now parsing fails because the classification sees ")" followed by a ":".
This a nasty one: we can't just bail out on "?" as that is useful for generic types. But once you accept "?" then it could be a conditional as well, and conditionals also feature a ":" which means here we have a problem.
I think "?" should only conditionally be accepted if we're inside generic brackets. But then again, you could still have `a < b ? c() : d` which is not a type.
-------------
PR: https://git.openjdk.org/jdk/pull/10798
More information about the compiler-dev
mailing list