mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ControlFlowAnalyzer: do not produce case-tests for invalid switch labels
GitOrigin-RevId: 8bc49191864fea56a3925f113892323f1cc7c58a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4c20010c0e
commit
52ee08cd92
+7
-3
@@ -943,12 +943,16 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
if (values != null) {
|
||||
for (PsiExpression caseValue : values.getExpressions()) {
|
||||
|
||||
boolean enumConstant = false;
|
||||
if (enumValues != null && caseValue instanceof PsiReferenceExpression) {
|
||||
//noinspection SuspiciousMethodCalls
|
||||
enumValues.remove(((PsiReferenceExpression)caseValue).resolve());
|
||||
PsiEnumConstant target = ObjectUtils.tryCast(((PsiReferenceExpression)caseValue).resolve(), PsiEnumConstant.class);
|
||||
if (target != null) {
|
||||
enumValues.remove(target);
|
||||
enumConstant = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (caseValue != null && expressionValue != null) {
|
||||
if (caseValue != null && expressionValue != null && (enumConstant || PsiUtil.isConstantExpression(caseValue))) {
|
||||
addInstruction(new PushInstruction(expressionValue, null));
|
||||
caseValue.accept(this);
|
||||
addInstruction(new BinopInstruction(
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import org.jetbrains.annotations.*;
|
||||
|
||||
class Test {
|
||||
void test(int x) {
|
||||
Integer y = null;
|
||||
switch (x) {
|
||||
case <error descr="Constant expression required">y</error>:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -668,4 +668,5 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testNullabilityAfterCastAndInstanceOf() { doTest(); }
|
||||
public void testInstanceOfTernary() { doTest(); }
|
||||
public void testStringContains() { doTest(); }
|
||||
public void testSwitchLabelNull() { doTest(); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user