mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] value break ref inside switch expression always resolves to a variable (IDEA-204204)
... even when a switch expression is not an innermost context of the break
This commit is contained in:
+1
-1
@@ -796,7 +796,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(message).create();
|
||||
}
|
||||
}
|
||||
else if (expression != null && !plainRef) {
|
||||
else if (expression != null && (!plainRef || ((PsiReferenceExpression)expression).resolve() instanceof PsiVariable)) {
|
||||
String message = JavaErrorMessages.message("value.break.unexpected");
|
||||
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(message).create();
|
||||
}
|
||||
|
||||
+9
-2
@@ -306,8 +306,15 @@ public class PsiReferenceExpressionImpl extends ExpressionPsiElement implements
|
||||
labels = new JavaResolveResult[]{new CandidateInfo(labeled, PsiSubstitutor.EMPTY)};
|
||||
}
|
||||
|
||||
PsiElement context = PsiImplUtil.findEnclosingSwitchOrLoop(breakStatement);
|
||||
if (!(context instanceof PsiSwitchExpression)) {
|
||||
boolean insideSwitchExpression = false;
|
||||
PsiElement context = breakStatement;
|
||||
while ((context = PsiImplUtil.findEnclosingSwitchOrLoop(context.getParent())) != null) {
|
||||
if (context instanceof PsiSwitchExpression) {
|
||||
insideSwitchExpression = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!insideSwitchExpression) {
|
||||
return labels;
|
||||
}
|
||||
else if (labels.length > 0) {
|
||||
|
||||
+17
-1
@@ -18,14 +18,30 @@ class ValueBreaks {
|
||||
|
||||
sink(switch (0) {
|
||||
case 0 -> { while (true) <error descr="Value break outside switch expression">break 42;</error> }
|
||||
case 1 -> { while (true) break <error descr="Undefined label: 'ref'">ref</error>; }
|
||||
case 1 -> { while (true) <error descr="Value break outside switch expression">break ref;</error> }
|
||||
case 2 -> { while (true) break <error descr="Undefined label: 'wtf'">wtf</error>; }
|
||||
case 3 -> { break ref; }
|
||||
case 4 -> { break (ref); }
|
||||
case 5 -> { break <error descr="Cannot resolve symbol 'wtf'">wtf</error>; }
|
||||
case 6 -> {
|
||||
int a = 0;
|
||||
a: switch (0) {
|
||||
default: break <error descr="Reference to 'a' is ambiguous, both 'a:' and 'variable a' match">a</error>;
|
||||
}
|
||||
}
|
||||
default -> throw new RuntimeException();
|
||||
});
|
||||
|
||||
switch (0) {
|
||||
case 0 -> { while (true) break <error descr="Undefined label: 'ref'">ref</error>; }
|
||||
case 1 -> {
|
||||
int a = 0;
|
||||
a: switch (0) {
|
||||
default: break a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ref: sink(switch (0) {
|
||||
default: break <error descr="Reference to 'ref' is ambiguous, both 'ref:' and 'ValueBreaks.ref' match">ref</error>;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user