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
@@ -1,11 +0,0 @@
// KT-7186: False "Type mismatch" error
fun indexOfMax(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
// KT-7186: False "Type mismatch" error
fun indexOfMax(a: IntArray): Int? {
@@ -0,0 +1,38 @@
fun foo(x: Int, y: Any?, z: Int) {}
fun myRun(block: () -> Unit): Any? {
return null
}
fun test_1() {
var x: String? = null
if (x != null) {
foo(
x.length, // stable smartcast
run { x = "" },
x.length // stable smartcast
)
}
}
fun test_2() {
var x: String? = null
if (x != null) {
foo(
x.length, // stable smartcast
myRun { x = "" },
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // unstable smartcast
)
}
}
fun test_3() {
var x: String? = null
if (x != null) {
foo(
x.length, // stable smartcast
{ x = "" },
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // stable smartcast
)
}
}
@@ -0,0 +1,38 @@
fun foo(x: Int, y: Any?, z: Int) {}
fun myRun(block: () -> Unit): Any? {
return null
}
fun test_1() {
var x: String? = null
if (x != null) {
foo(
<!DEBUG_INFO_SMARTCAST!>x<!>.length, // stable smartcast
run { x = "" },
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // stable smartcast
)
}
}
fun test_2() {
var x: String? = null
if (x != null) {
foo(
<!DEBUG_INFO_SMARTCAST!>x<!>.length, // stable smartcast
myRun { x = "" },
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // unstable smartcast
)
}
}
fun test_3() {
var x: String? = null
if (x != null) {
foo(
<!DEBUG_INFO_SMARTCAST!>x<!>.length, // stable smartcast
{ x = "" },
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // stable smartcast
)
}
}
@@ -0,0 +1,8 @@
package
public fun foo(/*0*/ x: kotlin.Int, /*1*/ y: kotlin.Any?, /*2*/ z: kotlin.Int): kotlin.Unit
public fun myRun(/*0*/ block: () -> kotlin.Unit): kotlin.Any?
public fun test_1(): kotlin.Unit
public fun test_2(): kotlin.Unit
public fun test_3(): kotlin.Unit