Skip to content

Commit

Permalink
Don't require // fall out comments on expression switches
Browse files Browse the repository at this point in the history
#2709

PiperOrigin-RevId: 565736512
  • Loading branch information
cushon authored and Error Prone Team committed Sep 15, 2023
1 parent 19fefad commit 4dd1c78
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Description matchSwitch(SwitchTree tree, VisitorState state) {
}
CaseTree defaultCase = maybeDefault.get();
List<? extends StatementTree> statements = defaultCase.getStatements();
if (statements != null && !statements.isEmpty()) {
if (statements == null || !statements.isEmpty()) {
return NO_MATCH;
}
// If `default` case is empty, and last in switch, add `// fall out` comment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,23 @@ public void arrowSwitchNegative() {
"}")
.doTest();
}

@Test
public void arrowComment() {
assumeTrue(RuntimeVersion.isAtLeast14());
compilationHelper
.addSourceLines(
"Test.java",
"class Test {",
" void f() {}",
" void m(int i) {",
" switch (i) {",
" case 0 -> f();",
" case 1 -> f();",
" default -> f();",
" }",
" }",
"}")
.doTest();
}
}

0 comments on commit 4dd1c78

Please sign in to comment.