From 366ab508e142257b6fd27db2d6de328873913921 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 20 Jan 2016 19:53:43 +0300 Subject: [PATCH] Data flow analysis: assignment of null makes variable effectively of type 'Nothing?' --- .../resolve/calls/smartcasts/DelegatingDataFlowInfo.kt | 7 ++++--- .../diagnostics/tests/BinaryCallsOnNullableValues.kt | 6 +++--- .../diagnostics/tests/smartCasts/varnotnull/varIntNull.kt | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt index 59ebca6b5b5..6145db336c4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt @@ -144,9 +144,10 @@ internal class DelegatingDataFlowInfo private constructor( val newTypeInfo = newTypeInfo() var typesForB = getPredictableTypes(b) // Own type of B must be recorded separately, e.g. for a constant - // But if its type is the same as A or it's null, there is no reason to do it - // because usually null type or own type are not saved in this set - if (nullabilityOfB.canBeNonNull() && a.type != b.type) { + // But if its type is the same as A, there is no reason to do it + // because own type is not saved in this set + // Error types are also not saved + if (!b.type.isError && a.type != b.type) { typesForB += b.type } newTypeInfo.putAll(a, typesForB) diff --git a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt index 7bef37310d9..49502e607d4 100644 --- a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt +++ b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt @@ -5,10 +5,10 @@ class A() { fun f(): Unit { var x: Int? = 1 x = null - x + 1 - x plus 1 + x + 1 + x plus 1 x < 1 - x += 1 + x += 1 x == 1 x != 1 diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.kt index 63c85f364b7..0675e3e7288 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/varIntNull.kt @@ -1,5 +1,5 @@ fun foo(): Int { var i: Int? = 42 i = null - return i + 1 + return i + 1 } \ No newline at end of file