RFR: 8294943: Implement record patterns in enhanced for [v8]
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Nov 11 18:06:32 UTC 2022
On Fri, 11 Nov 2022 17:34:37 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:
>> src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java line 2987:
>>
>>> 2985: boolean inType = false;
>>> 2986: boolean inSelectionAndParenthesis = false;
>>> 2987: boolean sequentialIdentifiers = false;
>>
>> In general the changes look good - but please make sure that we don't get confused by lambda expressions. E.g. a lambda can be like `(type name)`, so you have two identifiers between parens. Or, even `(int x)`, so `int x` between parens - which I think will trick this code into thinking you have a record?
>
> This qualifies as a test case to add and a new bug to fix :D
> Good catch.
>
>
> static <T> void method2(Function<Integer, Integer> f) {}
> int i = 42;
> for (method2((Integer a) -> 42); i == 0;) { i++; }
Note also that a generic type might end with `>` - so `>` followed by an IDENT could also be a sign or a record (same as IDENT IDENT).
-------------
PR: https://git.openjdk.org/jdk/pull/10798
More information about the compiler-dev
mailing list