RFR: 8335766: Switch case with pattern matching and guard clause compiles inconsistently
Jan Lahoda
jlahoda at openjdk.org
Tue Jul 9 08:31:01 UTC 2024
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
-------------
Commit messages:
- 8335766: Switch case with pattern matching and guard clause compiles inconsistently
Changes: https://git.openjdk.org/jdk/pull/20093/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=20093&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8335766
Stats: 14 lines in 2 files changed: 12 ins; 0 del; 2 mod
Patch: https://git.openjdk.org/jdk/pull/20093.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/20093/head:pull/20093
PR: https://git.openjdk.org/jdk/pull/20093
More information about the compiler-dev
mailing list