[jdk17] RFR: 8268320: Better error recovery for broken patterns in switch [v2]

Jan Lahoda jlahoda at openjdk.java.net
Fri Jun 25 13:40:30 UTC 2021


> [a copy of https://github.com/openjdk/jdk/pull/4441 for JDK 17]
> 
> Trying to improve error recovery in case the user wanted to use a type-pattern in the switch construct, but didn't put a binding variable name after the type name. E.g.:
> 
> $ cat test/langtools/tools/javac/diags/examples/PatternExpected.java
> [snip]
> class PatternSwitch {
>     private void doSwitch(Object o) {
>         switch (o) {
>             case String: break;
>             default: break;
>         }
>     }
> }
> $ javac --enable-preview -source 17  test/langtools/tools/javac/diags/examples/PatternExpected.java
> test/langtools/tools/javac/diags/examples/PatternExpected.java:32: error: type pattern expected
>             case String: break;
>                  ^
> Note: test/langtools/tools/javac/diags/examples/PatternExpected.java uses preview features of Java SE 17.
> Note: Recompile with -Xlint:preview for details.
> 1 error

Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:

  Fixing output.

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

Changes:
  - all: https://git.openjdk.java.net/jdk17/pull/146/files
  - new: https://git.openjdk.java.net/jdk17/pull/146/files/f8264177..bf7a7109

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk17&pr=146&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk17&pr=146&range=00-01

  Stats: 3 lines in 1 file changed: 2 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk17/pull/146.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/146/head:pull/146

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


More information about the compiler-dev mailing list