Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error formatting switch blocks with arrow labels #507

Closed
skirkpatrick opened this issue Jul 15, 2020 · 4 comments
Closed

Error formatting switch blocks with arrow labels #507

skirkpatrick opened this issue Jul 15, 2020 · 4 comments

Comments

@skirkpatrick
Copy link

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)
@tbroyer
Copy link
Contributor

tbroyer commented Jul 15, 2020

Duplicate of #477 ?

@skirkpatrick
Copy link
Author

skirkpatrick commented Jul 15, 2020

#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...

@skirkpatrick
Copy link
Author

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

@tbroyer
Copy link
Contributor

tbroyer commented Jul 15, 2020

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants