unknown variables should not be nullable-enabled after instanceof

This commit is contained in:
peter
2013-09-28 15:01:51 +02:00
parent f32fb52280
commit 6b0b1bc5da
3 changed files with 16 additions and 0 deletions
@@ -585,9 +585,13 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
}
return applyCondition(compareToNull(dfaVar, false));
}
boolean wasUnknown = getVariableState(dfaVar).getNullability() == Nullness.UNKNOWN;
if (applyCondition(compareToNull(dfaVar, true))) {
DfaVariableState newState = getVariableState(dfaVar).withInstanceofValue((DfaTypeValue)dfaRight);
if (newState != null) {
if (wasUnknown) {
newState = newState.withNullability(Nullness.UNKNOWN);
}
setVariableState(dfaVar, newState);
return true;
}
@@ -0,0 +1,11 @@
class Some {
void foo(Object o) {
if (o instanceof String) {
}
o.hashCode();
}
}
@@ -308,6 +308,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testVariablesDiverge() { doTest(); }
public void testDontForgetInstanceofInfoWhenMerging() { doTest(); }
public void testDontMakeNullableAfterInstanceof() { doTest(); }
public void _testNullCheckBeforeInstanceof() { doTest(); } // http://youtrack.jetbrains.com/issue/IDEA-113220
}