mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Highlight unreachable assignment of array element (IDEA-199556)
This commit is contained in:
@@ -1324,6 +1324,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
myStartStatementStack.pushStatement(rExpr == null ? expression : rExpr, false);
|
||||
myEndStatementStack.pushStatement(rExpr == null ? expression : rExpr, false);
|
||||
|
||||
boolean generatedWriteInstruction = false;
|
||||
PsiExpression lExpr = PsiUtil.skipParenthesizedExprDown(expression.getLExpression());
|
||||
if (lExpr instanceof PsiReferenceExpression) {
|
||||
PsiVariable variable = getUsedVariable((PsiReferenceExpression)lExpr);
|
||||
@@ -1344,6 +1345,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
rExpr.accept(this);
|
||||
}
|
||||
generateWriteInstruction(variable);
|
||||
generatedWriteInstruction = true;
|
||||
|
||||
if (myAssignmentTargetsAreElements) finishElement(lExpr);
|
||||
}
|
||||
@@ -1376,6 +1378,8 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
rExpr.accept(this);
|
||||
}
|
||||
}
|
||||
//each statement should contain at least one instruction in order to getElement(offset) work
|
||||
if (!generatedWriteInstruction) emitEmptyInstruction();
|
||||
|
||||
myStartStatementStack.popStatement();
|
||||
myEndStatementStack.popStatement();
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class C {
|
||||
void foo(String arg) throws Exception {
|
||||
Object[] objects;
|
||||
throw new Exception("");
|
||||
<error descr="Unreachable statement">objects[0] = arg;</error>
|
||||
}
|
||||
}
|
||||
+2
@@ -418,6 +418,8 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testUnreachableArrayElementAssignment() { doTest(false); }
|
||||
|
||||
public void testInsane() {
|
||||
configureFromFileText("x.java", "class X { \nx_x_x_x\n }");
|
||||
List<HighlightInfo> infos = highlightErrors();
|
||||
|
||||
Reference in New Issue
Block a user