[FIR] Implement new bound smartcast algorithm
#KT-36055 Fixed
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ fun foo() {
|
||||
v = "abc"
|
||||
v.length
|
||||
v = null
|
||||
v.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
v.<!INAPPLICABLE_CANDIDATE!>length<!>
|
||||
v = "abc"
|
||||
v.length
|
||||
}
|
||||
+2
-2
@@ -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<!>()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -44,7 +44,7 @@ fun gaz(s: String?) {
|
||||
x = null
|
||||
}
|
||||
run {
|
||||
x.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
|
||||
x.hashCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -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()
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
|
||||
+1
-1
@@ -16,5 +16,5 @@ fun list(start: SomeObject) {
|
||||
e = e.next()
|
||||
}
|
||||
// e can be null because of next()
|
||||
e.<!INAPPLICABLE_CANDIDATE!>doSomething<!>()
|
||||
e.doSomething()
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
|
||||
+1
-1
@@ -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<!>
|
||||
}
|
||||
+1
-1
@@ -6,5 +6,5 @@ fun foo() {
|
||||
try {
|
||||
s = null
|
||||
} catch (ex: Exception) {}
|
||||
s.<!UNRESOLVED_REFERENCE!>hashCode<!>()
|
||||
s.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
|
||||
}
|
||||
+1
-1
@@ -12,5 +12,5 @@ fun foo() {
|
||||
finally {
|
||||
bar()
|
||||
}
|
||||
s.<!UNRESOLVED_REFERENCE!>hashCode<!>()
|
||||
s.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
|
||||
}
|
||||
+1
-1
@@ -6,5 +6,5 @@ fun foo() {
|
||||
try {
|
||||
s = null
|
||||
} catch (ex: Exception) {}
|
||||
s.<!UNRESOLVED_REFERENCE!>hashCode<!>()
|
||||
s.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
}
|
||||
+1
-1
@@ -13,5 +13,5 @@ fun list(start: SomeObject) {
|
||||
e = e.next()
|
||||
}
|
||||
// e can be null because of next()
|
||||
e.<!INAPPLICABLE_CANDIDATE!>doSomething<!>()
|
||||
e.doSomething()
|
||||
}
|
||||
Reference in New Issue
Block a user