More precise diagnostics of smart cast impossible #KT-7240 Fixed

This commit is contained in:
Mikhail Glukhikh
2015-11-02 17:56:31 +03:00
parent 16a8e8f6f0
commit 41ebfd025e
31 changed files with 94 additions and 73 deletions
@@ -92,7 +92,7 @@ public object RuntimeAssertionsTypeChecker : AdditionalTypeChecker {
expressionType,
object : RuntimeAssertionInfo.DataFlowExtras {
override val canBeNull: Boolean
get() = c.dataFlowInfo.getNullability(dataFlowValue).canBeNull()
get() = c.dataFlowInfo.getPredictableNullability(dataFlowValue).canBeNull()
override val possibleTypes: Set<KotlinType>
get() = c.dataFlowInfo.getPossibleTypes(dataFlowValue)
override val presentableText: String
@@ -71,7 +71,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
if (TypeUtils.noExpectedType(expectedType)) return
val expectedMustNotBeNull = expectedType.mustNotBeNull()
if (dataFlowInfo.getNullability(dataFlowValue) == Nullability.NOT_NULL) return
if (dataFlowInfo.getPredictableNullability(dataFlowValue) == Nullability.NOT_NULL) return
val actualMayBeNull = expressionType.mayBeNull()
@@ -155,7 +155,7 @@ public class JavaNullabilityWarningsChecker : AdditionalTypeChecker {
}
private fun <T: Any> doIfNotNull(dataFlowValue: DataFlowValue, c: ResolutionContext<*>, body: () -> T): T? {
if (c.dataFlowInfo.getNullability(dataFlowValue).canBeNull()
if (c.dataFlowInfo.getPredictableNullability(dataFlowValue).canBeNull()
&& dataFlowValue.type.mustNotBeNull() == ErrorsJvm.NullabilityInformationSource.JAVA) {
return body()
}