[jdk17] RFR: 8268961: Parenthesized pattern with guards does not work

Jan Lahoda jlahoda at openjdk.java.net
Tue Jun 22 13:10:13 UTC 2021


This PR fixes a couple of problems related to parenthesized patterns:
a) as noted in https://bugs.openjdk.java.net/browse/JDK-8268961, javac does not accept guards after parenthesized patterns (e.g. `(String s) && s.isEmpty()`, although it should.
b) related to that, the disambiguation determining whether a case label is a pattern or an expression is not working well for cases like `a >> b`, which will be interpreted as a pattern (while it may be a valid expression)
c) related to that, handling of parenthesized patterns in Attr should also be better - the raw type warning should be reported for all type patterns, even those inside a guarded pattern
d) the source level check was missing on one place for parenthesized patterns, as noted in https://bugs.openjdk.java.net/browse/JDK-8268896

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

Commit messages:
 - Improving handling of parenthesized and guarded pattern types.
 - 8268961: Parenthesized pattern with guards does not work
 - 8268896: Parenthesized pattern is not guarded by source level check

Changes: https://git.openjdk.java.net/jdk17/pull/116/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk17&pr=116&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8268961
  Stats: 274 lines in 8 files changed: 244 ins; 19 del; 11 mod
  Patch: https://git.openjdk.java.net/jdk17/pull/116.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/116/head:pull/116

PR: https://git.openjdk.java.net/jdk17/pull/116


More information about the compiler-dev mailing list