FIR checker: report SMARTCAST_IMPOSSIBLE for local variables

This commit is contained in:
Tianyu Geng
2021-05-13 17:23:18 -07:00
committed by TeamCityServer
parent 092750e215
commit 0ecc752813
38 changed files with 792 additions and 99 deletions
@@ -27,10 +27,10 @@ fun baz(s: String?) {
var x = s
if (x != null) {
run {
x.hashCode()
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
}
run {
x<!UNSAFE_CALL!>.<!>hashCode()
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
x = null
}
}
@@ -40,11 +40,11 @@ fun gaz(s: String?) {
var x = s
if (x != null) {
run {
x<!UNSAFE_CALL!>.<!>hashCode()
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
x = null
}
run {
x<!UNSAFE_CALL!>.<!>hashCode()
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
}
}
}
@@ -53,7 +53,7 @@ fun gav(s: String?) {
var x = s
if (x != null) {
run {
x.hashCode()
<!SMARTCAST_IMPOSSIBLE!>x<!>.hashCode()
}
x = null
}
@@ -1,17 +0,0 @@
public fun foo() {
var s: String? = ""
fun closure(): Int {
if (s == "") {
s = null
return -1
} else if (s == null) {
return -2
} else {
return s.length // Here smartcast is possible, at least in principle
}
}
if (s != null) {
System.out.println(closure())
System.out.println(s.length) // Here smartcast is not possible due to a closure predecessor
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
public fun foo() {
var s: String? = ""
fun closure(): Int {
@@ -14,4 +15,4 @@ public fun foo() {
System.out.println(closure())
System.out.println(<!SMARTCAST_IMPOSSIBLE!>s<!>.length) // Here smartcast is not possible due to a closure predecessor
}
}
}
@@ -1,15 +0,0 @@
// See also KT-7186
fun IntArray.forEachIndexed( op: (i: Int, value: Int) -> Unit) {
for (i in 0..this.size)
op(i, this[i])
}
fun max(a: IntArray): Int? {
var maxI: Int? = null
a.forEachIndexed { i, value ->
if (maxI == null || value >= a[maxI])
maxI = i
}
return maxI
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// See also KT-7186
fun IntArray.forEachIndexed( op: (i: Int, value: Int) -> Unit) {