Better error recovery for broken patterns in switch

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 17
    • Affects Version/s: 17
    • Component/s: tools
    • None
    • b29

        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.

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

                Created:
                Updated:
                Resolved: