Data flow analysis: assignment of null makes variable effectively of type 'Nothing?'

This commit is contained in:
Mikhail Glukhikh
2016-01-20 19:53:43 +03:00
parent 859059d714
commit 366ab508e1
3 changed files with 8 additions and 7 deletions
@@ -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)
@@ -5,10 +5,10 @@ class A() {
fun f(): Unit {
var x: Int? = <!VARIABLE_WITH_REDUNDANT_INITIALIZER!>1<!>
x = null
<!DEBUG_INFO_CONSTANT!>x<!> <!UNSAFE_INFIX_CALL!>+<!> 1
<!DEBUG_INFO_CONSTANT!>x<!> <!UNSAFE_INFIX_CALL, INFIX_MODIFIER_REQUIRED!>plus<!> 1
<!DEBUG_INFO_CONSTANT!>x<!> + 1
<!DEBUG_INFO_CONSTANT!>x<!> <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
<!DEBUG_INFO_CONSTANT!>x<!> <!UNSAFE_INFIX_CALL!><<!> 1
<!DEBUG_INFO_CONSTANT!>x<!> <!UNSAFE_INFIX_CALL!>+=<!> 1
<!TYPE_MISMATCH!><!DEBUG_INFO_CONSTANT!>x<!> += 1<!>
<!DEBUG_INFO_CONSTANT!>x<!> == 1
<!DEBUG_INFO_CONSTANT!>x<!> != 1
@@ -1,5 +1,5 @@
fun foo(): Int {
var i: Int? = <!VARIABLE_WITH_REDUNDANT_INITIALIZER!>42<!>
i = null
return <!DEBUG_INFO_CONSTANT!>i<!> <!UNSAFE_INFIX_CALL!>+<!> 1
return <!TYPE_MISMATCH!><!DEBUG_INFO_CONSTANT!>i<!> + 1<!>
}