FIR CFG: handle loops and try/catch when analyzing smartcasts in lambdas

See KT-50092
This commit is contained in:
pyos
2022-09-30 14:29:55 +03:00
committed by teamcity
parent d054617b8e
commit a9ae1fcdf9
8 changed files with 339 additions and 116 deletions
@@ -0,0 +1,55 @@
// ISSUE: KT-50092
fun test1() {
var x: String? = "..."
var lambda: (() -> Int)? = null
for (i in 1..2) {
when (i) {
2 -> x = null
1 -> if (x != null) lambda = { <!DEBUG_INFO_SMARTCAST!>x<!>.length } // bad
}
}
lambda?.invoke()
}
fun test2() {
var x: String? = "..."
if (x != null) {
val lambda = { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } // bad
while (false) return
x = null
lambda()
}
}
fun test3() {
var x: String? = "asd"
if (x != null) {
var lambda: (() -> Int)? = null
try {
lambda = { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } // bad
if (true) throw RuntimeException("...")
return
} catch (e: Exception) {
x = null
lambda?.invoke()
} finally {
x = null
lambda?.invoke()
}
}
}
fun test4() {
var x: String? = "..."
if (x != null) {
var lambda: (() -> Int)? = <!VARIABLE_WITH_REDUNDANT_INITIALIZER!>null<!>
while (true) {
lambda = { <!SMARTCAST_IMPOSSIBLE!>x<!>.length } // bad
if (true) break
return
}
x = null
lambda?.invoke()
}
}