[jdk23] RFR: 8335766: Switch case with pattern matching and guard clause compiles inconsistently
Vicente Romero
vromero at openjdk.org
Thu Jul 11 01:49:00 UTC 2024
On Wed, 10 Jul 2024 12:24:38 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> Hi all,
>
> This pull request contains a backport of commit [537d20af](https://github.com/openjdk/jdk/commit/537d20afbff255489a7b1bdb0410b9d1aba715b7) from the [openjdk/jdk](https://git.openjdk.org/jdk) repository.
>
> The commit being backported was authored by Jan Lahoda on 10 Jul 2024 and was reviewed by Aggelos Biboudis.
>
> Thanks!
>
> Original description:
> 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
lgtm
-------------
Marked as reviewed by vromero (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/20111#pullrequestreview-2170713037
More information about the compiler-dev
mailing list