mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
switch expression: missed error on continue without lbl outside of switch (IDEA-204208)
This commit is contained in:
+10
-3
@@ -805,13 +805,13 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static HighlightInfo checkContinueOutsideLoop(@NotNull PsiContinueStatement statement) {
|
||||
static HighlightInfo checkContinueOutsideLoop(@NotNull PsiContinueStatement statement, LanguageLevel languageLevel) {
|
||||
if (PsiImplUtil.findEnclosingLoop(statement) == null) {
|
||||
String message = JavaErrorMessages.message("continue.outside.loop");
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(message).create();
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
return checkContinueOutsideOfSwitchExpression(statement,statement.findContinuedStatement(), languageLevel);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -827,12 +827,19 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(message).create();
|
||||
}
|
||||
|
||||
return checkContinueOutsideOfSwitchExpression(statement, continuedStatement, level);
|
||||
}
|
||||
|
||||
private static HighlightInfo checkContinueOutsideOfSwitchExpression(@NotNull PsiContinueStatement statement,
|
||||
PsiStatement continuedStatement,
|
||||
@NotNull LanguageLevel level) {
|
||||
if (level.isAtLeast(LanguageLevel.JDK_12_PREVIEW)) {
|
||||
PsiElement enclosing = PsiImplUtil.findEnclosingSwitchOrLoop(statement);
|
||||
if (enclosing instanceof PsiSwitchExpression && PsiTreeUtil.isAncestor(continuedStatement, enclosing, true)) {
|
||||
String message = JavaErrorMessages.message("continue.outside.switch.expr");
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(message).create();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
+1
-1
@@ -454,7 +454,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
super.visitContinueStatement(statement);
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
PsiIdentifier label = statement.getLabelIdentifier();
|
||||
myHolder.add(label == null ? HighlightUtil.checkContinueOutsideLoop(statement)
|
||||
myHolder.add(label == null ? HighlightUtil.checkContinueOutsideLoop(statement, myLanguageLevel)
|
||||
: HighlightUtil.checkContinueTarget(statement, label, myLanguageLevel));
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -54,6 +54,7 @@ class SwitchExpressions {
|
||||
System.out.println(switch (new Random().nextInt()) {
|
||||
case -1: <error descr="Return outside of enclosing switch expression">return;</error>
|
||||
case -2: <error descr="Continue outside of enclosing switch expression">continue lab;</error>
|
||||
case -3: <error descr="Continue outside of enclosing switch expression">continue;</error>
|
||||
default: <error descr="Break outside of enclosing switch expression">break lab;</error>
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user