[FIR] Implement new bound smartcast algorithm

#KT-36055 Fixed
This commit is contained in:
Dmitriy Novozhilov
2020-02-10 17:14:58 +03:00
parent 40f907ec2f
commit 6735cc8937
103 changed files with 2197 additions and 309 deletions
@@ -5,7 +5,7 @@ fun foo() {
v = "abc"
v.length
v = null
v.<!UNRESOLVED_REFERENCE!>length<!>
v.<!INAPPLICABLE_CANDIDATE!>length<!>
v = "abc"
v.length
}
@@ -6,7 +6,7 @@ fun foo() {
val y = x
x = null
if (y != null) {
x.<!UNRESOLVED_REFERENCE!>hashCode<!>()
x.hashCode()
}
}
@@ -23,7 +23,7 @@ fun bar(s: String?) {
val hashCode = ss?.hashCode()
ss = null
if (hashCode != null) {
ss.<!UNRESOLVED_REFERENCE!>hashCode<!>()
ss.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
}
}
@@ -44,7 +44,7 @@ fun gaz(s: String?) {
x = null
}
run {
x.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
x.hashCode()
}
}
}
@@ -11,11 +11,11 @@ fun list(start: SomeObject) {
// In theory smart cast is possible here
// But in practice we have a loop with changing e
// ?: should we "or" entrance type info with condition type info?
if (<!UNRESOLVED_REFERENCE!>!<!>e.<!INAPPLICABLE_CANDIDATE!>doSomething<!>())
if (!e.doSomething())
break
// Smart cast here is still not possible
e = e.<!INAPPLICABLE_CANDIDATE!>next<!>()
e = e.next()
} while (e != null)
// e can be null because of next()
e.<!INAPPLICABLE_CANDIDATE!>doSomething<!>()
e.doSomething()
}
@@ -8,5 +8,5 @@ public fun foo(pp: String?): Int {
p = null
} while (!x())
// Smart cast is NOT possible here
return p.<!INAPPLICABLE_CANDIDATE!>length<!>
return p.length
}
@@ -9,8 +9,8 @@ fun list(start: SomeObject): SomeObject {
var e: SomeObject? = start
for (i in 0..42) {
// Unsafe calls because of nullable e at the beginning
e.<!INAPPLICABLE_CANDIDATE!>doSomething<!>()
e = e.<!INAPPLICABLE_CANDIDATE!>next<!>()
e.doSomething()
e = e.next()
}
// Smart cast is not possible here due to next()
return e
@@ -16,5 +16,5 @@ fun list(start: SomeObject) {
e = e.next()
}
// e can be null because of next()
e.<!INAPPLICABLE_CANDIDATE!>doSomething<!>()
e.doSomething()
}
@@ -76,5 +76,5 @@ fun test6() {
finally {
a = null
}
a.<!UNRESOLVED_REFERENCE!>hashCode<!>() // a is null here
a.<!INAPPLICABLE_CANDIDATE!>hashCode<!>() // a is null here
}
@@ -4,5 +4,5 @@ fun foo() {
// It is possible in principle to provide smart cast here
v.<!INAPPLICABLE_CANDIDATE!>length<!>
v = null
v.<!UNRESOLVED_REFERENCE!>length<!>
v.<!INAPPLICABLE_CANDIDATE!>length<!>
}
@@ -6,5 +6,5 @@ fun foo() {
try {
s = null
} catch (ex: Exception) {}
s.<!UNRESOLVED_REFERENCE!>hashCode<!>()
s.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
}
@@ -12,5 +12,5 @@ fun foo() {
finally {
bar()
}
s.<!UNRESOLVED_REFERENCE!>hashCode<!>()
s.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
}
@@ -6,5 +6,5 @@ fun foo() {
try {
s = null
} catch (ex: Exception) {}
s.<!UNRESOLVED_REFERENCE!>hashCode<!>()
s.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
}
@@ -2,5 +2,5 @@
fun foo(): Int {
var i: Int? = 42
i = null
return i + 1
return i <!INAPPLICABLE_CANDIDATE!>+<!> 1
}
@@ -2,5 +2,5 @@
fun foo(): Int {
var s: String? = "abc"
s = null
return s.<!UNRESOLVED_REFERENCE!>length<!>
return s.<!INAPPLICABLE_CANDIDATE!>length<!>
}
@@ -9,5 +9,5 @@ public fun foo(pp: String?): Int {
}
// Smart cast is NOT possible here
// (we could provide it but p = null makes it much harder)
return p.<!INAPPLICABLE_CANDIDATE!>length<!>
return p.length
}
@@ -9,5 +9,5 @@ public fun foo(pp: String?): Int {
}
// Smart cast is NOT possible here
// (we could provide it but p = null makes it much harder)
return p.<!INAPPLICABLE_CANDIDATE!>length<!>
return p.length
}
@@ -9,5 +9,5 @@ public fun foo(pp: String?): Int {
}
// Smart cast is NOT possible here
// (we could provide it but p = null makes it much harder)
return p.<!INAPPLICABLE_CANDIDATE!>length<!>
return p.length
}
@@ -13,5 +13,5 @@ fun list(start: SomeObject) {
e = e.next()
}
// e can be null because of next()
e.<!INAPPLICABLE_CANDIDATE!>doSomething<!>()
e.doSomething()
}