RFR: 8335766: Switch case with pattern matching and guard clause compiles inconsistently
Aggelos Biboudis
abimpoudis at openjdk.org
Tue Jul 9 09:29:32 UTC 2024
On Tue, 9 Jul 2024 08:26:50 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> When javac parser see a `case` label, it needs to disambiguate between expressions (constant labels) and patterns. But, for code like:
>
> case R(int x) when (x > 0)
>
>
> the parser will try to parse the label as an expression, which is obviously not correct. The problem is that it does not disambiguate before `when`, and there indeed is an expression after `when`.
>
> The proposal is to disambiguate as a pattern once there is `when` after a closing parenthesis at the top-level. This should prevent the code to even look at the `when` expression
Looks good.
-------------
Marked as reviewed by abimpoudis (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/20093#pullrequestreview-2165659910
More information about the compiler-dev
mailing list