TrackingRunner: prefer reporting exact place where relation was established (IDEA-238060)

GitOrigin-RevId: 2f476f1ab1ed75530cb21597d199e86c49703b10
This commit is contained in:
Tagir Valeev
2020-05-15 09:43:28 +00:00
committed by intellij-monorepo-bot
parent 5398b343e8
commit 103a0c382b
3 changed files with 32 additions and 20 deletions
@@ -1382,26 +1382,18 @@ public class TrackingRunner extends DataFlowRunner {
}
private static MemoryStateChange findRelationAddedChange(MemoryStateChange history, DfaVariableValue var, Relation relation) {
List<RelationType> subRelations;
switch (relation.myRelationType) {
case NE:
if (relation.myCounterpart.getDfType() instanceof DfConstantType) {
return history.findRelation(var, rel -> rel.equals(relation) ||
rel.myRelationType == RelationType.EQ &&
rel.myCounterpart.getDfType() instanceof DfConstantType,
true);
}
subRelations = Arrays.asList(RelationType.NE, RelationType.GT, RelationType.LT);
break;
case LE:
subRelations = Arrays.asList(RelationType.EQ, RelationType.LT);
break;
case GE:
subRelations = Arrays.asList(RelationType.EQ, RelationType.GT);
break;
default:
subRelations = Collections.singletonList(relation.myRelationType);
if (relation.myRelationType == RelationType.NE && relation.myCounterpart.getDfType() instanceof DfConstantType) {
return history.findRelation(var, rel -> rel.equals(relation) ||
rel.myRelationType == RelationType.EQ &&
rel.myCounterpart.getDfType() instanceof DfConstantType,
true);
}
return history.findRelation(var, rel -> rel.myCounterpart == relation.myCounterpart && subRelations.contains(rel.myRelationType), true);
MemoryStateChange exact = history.findRelation(var, rel -> rel.myCounterpart == relation.myCounterpart &&
relation.myRelationType.equals(rel.myRelationType), true);
if (exact != null) {
return exact;
}
return history.findRelation(var, rel -> rel.myCounterpart == relation.myCounterpart &&
relation.myRelationType.isSubRelation(rel.myRelationType), true);
}
}
@@ -0,0 +1,19 @@
/*
Value is always false (i == expected; line#15)
Condition 'i != expected' was checked before (i == expected; line#9)
*/
class A
void compareInts(int i) {
int expected = new Random().nextInt(100);
int result;
if (i == expected) {
result = 0;
}
else if (i < expected) {
result = -1;
}
else if (<selection>i == expected</selection>) {
result = 0;
}
}
}
@@ -182,4 +182,5 @@ public class DataFlowInspectionTrackerTest extends LightJavaCodeInsightFixtureTe
public void testMergeOnAnd() { doTest(); }
public void testPassedNotNull() { doTest(); }
public void testClassCheckInStream() { doTest(); }
public void testEqualsLessEquals() { doTest(); }
}