mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-151355 Wrong 'condition always false' after using decrement on object field
This commit is contained in:
+5
-8
@@ -1667,14 +1667,11 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
}
|
||||
|
||||
private void flushIncrementedValue(@Nullable PsiExpression operand) {
|
||||
if (operand instanceof PsiReferenceExpression && PsiUtil.isAccessedForWriting(operand)) {
|
||||
PsiVariable psiVariable = DfaValueFactory.resolveUnqualifiedVariable((PsiReferenceExpression)operand);
|
||||
if (psiVariable != null) {
|
||||
DfaVariableValue dfaVariable = myFactory.getVarFactory().createVariableValue(psiVariable, false);
|
||||
addInstruction(new FlushVariableInstruction(dfaVariable));
|
||||
if (psiVariable instanceof PsiField) {
|
||||
addInstruction(new FlushVariableInstruction(null));
|
||||
}
|
||||
DfaValue dfaVariable = operand == null ? null : myFactory.createValue(operand);
|
||||
if (dfaVariable instanceof DfaVariableValue && PsiUtil.isAccessedForWriting(operand)) {
|
||||
addInstruction(new FlushVariableInstruction((DfaVariableValue)dfaVariable));
|
||||
if (((DfaVariableValue)dfaVariable).getPsiVariable() instanceof PsiField) {
|
||||
addInstruction(new FlushVariableInstruction(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class Test {
|
||||
public class Node{
|
||||
private int var;
|
||||
}
|
||||
public void foo(Node n){
|
||||
assert(n.var>0);
|
||||
n.var--;
|
||||
if(n.var==0) { // condition always false
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,6 +238,7 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testLongCircuitOperations() { doTest(); }
|
||||
public void testUnconditionalForLoop() { doTest(); }
|
||||
public void testIncrementParenthesized() { doTest(); }
|
||||
public void testDecrementAnotherObjectField() { doTest(); }
|
||||
public void testAnonymousMethodIndependence() { doTest(); }
|
||||
public void testAnonymousFieldIndependence() { doTest(); }
|
||||
public void testNoConfusionWithAnonymousConstantInitializer() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user