Skip to content

Error formatting switch blocks with arrow labels #507

Closed

Description

@skirkpatrick

GJF gives the following error when formatting a file containing a switch statement using Java 14 arrow labels (case ... ->):

error: expected token: 'case'; generated ; instead

For example:

public class App {

  public void test(String subject) {
    switch (subject) {
      case "A" -> System.out.println("A");
      case "B" -> System.out.println("B");
    }
  }
}

GJF version: google-java-format-1.8-all-deps.jar
Java version:

openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.1+7)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.1+7, mixed mode, sharing)

Activity

  1. tbroyer commented on Jul 15, 2020

    @tbroyer
    Contributor

    Duplicate of #477 ?

  2. skirkpatrick commented on Jul 15, 2020

    @skirkpatrick
    Author

    #477 refers to switch expressions, and has been fixed in GJF 1.8.

    This issue specifically affects switch statements (non-value returning) using the arrow label syntax (traditional case ...: labels work fine)

    EDIT: actually, I could be wrong. Testing with the HEAD build...

  3. skirkpatrick commented on Jul 15, 2020

    @skirkpatrick
    Author

    @tbroyer you're correct, looks like this has already been fixed on master. Closing!

  4. tbroyer commented on Jul 15, 2020

    @tbroyer
    Contributor

    A test was added when adding support for yield in #489 (not sure which commit actually fixed it though):

    switch (i) {
    case 0 -> { System.out.println("0"); }
    default -> System.out.println("default");
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions