RFR: 8294943: Implement record patterns in enhanced for [v15]

Aggelos Biboudis abimpoudis at openjdk.org
Thu Nov 24 18:56:11 UTC 2022


On Thu, 24 Nov 2022 18:19:21 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> 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.
>
> Ok, after some offline discussion, I put together a patch which addresses these (and other) issues:
> 
> https://github.com/biboudis/jdk/pull/3
> 
> The core idea is to detect whether a `?` is part of a generic type or not. See the above PR for more details.
> 
> Sadly, one of the tests I've added seems to crash the compiler, because a type annotation is found in an unexpected place. So that needs more work.

This seems related to pattern matching in general (I left `?` out, since it happens with explicit types as well).

https://bugs.openjdk.org/browse/JDK-8297602

I am commenting out that line in your PR @mcimadamore and merging. The rest seem good.

Thanks for the investigation and the quick fix 🥇🥇🥇

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

PR: https://git.openjdk.org/jdk/pull/10798


More information about the compiler-dev mailing list