Data flow analysis: assignment of null makes variable effectively of type 'Nothing?'
This commit is contained in:
+4
-3
@@ -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<!>
|
||||
}
|
||||
Reference in New Issue
Block a user