Regression: getPredictableNullability for unnecessary safe call check #KT-10276 Fixed

This commit is contained in:
Mikhail Glukhikh
2015-12-08 10:04:37 +03:00
parent 2330ce2c28
commit 57b3bc0496
4 changed files with 28 additions and 1 deletions
@@ -429,7 +429,7 @@ public class CallExpressionResolver {
// Should be applied if we consider a safe call
if (element.getSafe()) {
DataFlowInfo dataFlowInfo = contextForSelector.dataFlowInfo;
if (dataFlowInfo.getNullability(receiverDataFlowValue).canBeNull()) {
if (dataFlowInfo.getPredictableNullability(receiverDataFlowValue).canBeNull()) {
contextForSelector = contextForSelector.replaceDataFlowInfo(
dataFlowInfo.disequate(receiverDataFlowValue, DataFlowValue.nullValue(builtIns)));
}
@@ -0,0 +1,11 @@
// See KT-10276
class Bar() {
var test: String? = null
fun foo() {
if (test != null) {
// No warning: test is a mutable property
test?.hashCode()
}
}
}
@@ -0,0 +1,10 @@
package
public final class Bar {
public constructor Bar()
public final var test: kotlin.String?
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -14766,6 +14766,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("falseUnnecessaryCall.kt")
public void testFalseUnnecessaryCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/falseUnnecessaryCall.kt");
doTest(fileName);
}
@TestMetadata("fieldExclExcl.kt")
public void testFieldExclExcl() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/fieldExclExcl.kt");