[java error highlighting] fix: highlight illegal fall-through when default case exists

GitOrigin-RevId: 686b3613a6fdf05d7e4d9af5e94fe977653ed9bd
This commit is contained in:
Alexandr Suhinin
2022-09-01 11:20:13 +03:00
committed by intellij-monorepo-bot
parent 5cf9b53cf4
commit 67998a0600
2 changed files with 12 additions and 1 deletions

View File

@@ -777,7 +777,9 @@ public class SwitchBlockHighlightingModel {
if (!(switchLabel instanceof PsiSwitchLabelStatement)) return;
PsiCaseLabelElementList labelElementList = switchLabel.getCaseLabelElementList();
if (labelElementList == null) continue;
List<PsiCaseLabelElement> patternElements = ContainerUtil.filter(labelElementList.getElements(), labelElement -> labelElement instanceof PsiPattern);
List<PsiCaseLabelElement> patternElements = ContainerUtil.filter(labelElementList.getElements(),
labelElement -> labelElement instanceof PsiPattern || labelElement instanceof PsiPatternGuard
);
if (patternElements.isEmpty()) continue;
PsiStatement prevStatement = PsiTreeUtil.getPrevSiblingOfType(firstSwitchLabelInGroup, PsiStatement.class);
if (prevStatement == null) continue;

View File

@@ -56,6 +56,15 @@ public class FallThrough {
System.out.println();
break;
}
switch (o) {
case Integer integer:
System.out.println(1);
case <error descr="Illegal fall-through to a pattern">String s when s.isEmpty()</error>:
System.out.println(2);
break;
default:
System.out.println(3);
}
switch (o) {
case String s:
break;