Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8268320

Better error recovery for broken patterns in switch

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 17
    • Fix Version/s: 17
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b29

      Backports

        Description

        As reported here:
        https://mail.openjdk.java.net/pipermail/core-libs-dev/2021-June/078693.html

        The error recovery could be improved in cases like:
        Object obj = ...;
        switch (obj) {
             case String -> {}
        }

        $ javac --enable-preview -source 17 /tmp/Test.java
        /tmp/Test.java:4: error: cannot find symbol
                     case String -> {}
                          ^
          symbol: variable String
          location: class Test

        Could produce an error suggesting there should be a pattern instead of a simple identifier.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                jlahoda Jan Lahoda
                Reporter:
                jlahoda Jan Lahoda
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: