dfa: treat different constants with same values as same (IDEA-121837)

This commit is contained in:
peter
2014-03-07 19:41:30 +01:00
parent 8084cb06ef
commit 3627c465e4
3 changed files with 42 additions and 3 deletions
@@ -89,11 +89,10 @@ public class DfaConstValue extends DfaValue {
if (TypeConversionUtil.isNumericType(type) && !TypeConversionUtil.isFloatOrDoubleType(type)) {
value = TypeConversionUtil.computeCastTo(value, PsiType.LONG);
}
Object key = constant != null ? constant : value;
DfaConstValue instance = myValues.get(key);
DfaConstValue instance = myValues.get(value);
if (instance == null) {
instance = new DfaConstValue(value, myFactory, constant);
myValues.put(key, instance);
myValues.put(value, instance);
}
return instance;
@@ -0,0 +1,38 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
class Doo {
static final int TYPE_1 = 20;
static final int TYPE_2 = 20;
public static void failedSecondCondition(int type) {
if(type != TYPE_1) {
return;
}
if(<warning descr="Condition 'type != TYPE_2' is always 'false'">type != TYPE_2</warning>) {
System.out.println();
}
}
}
class Doo2 {
static final int TYPE_1 = 200;
static final int TYPE_2 = 200;
public static void failedSecondCondition(int type) {
if(type != TYPE_1) {
return;
}
if(<warning descr="Condition 'type != TYPE_2' is always 'false'">type != TYPE_2</warning>) {
System.out.println();
}
}
}
@@ -309,6 +309,8 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testUnusedCallDoesNotMakeUnknown() { doTest(); }
public void testGettersAndPureNoFlushing() { doTest(); }
public void testSameComparisonTwice() { doTest(); }
public void testParametersAreNonnullByDefault() {
myFixture.addClass("package javax.annotation; public @interface ParametersAreNonnullByDefault {}");
myFixture.addClass("package javax.annotation; public @interface ParametersAreNullableByDefault {}");