Fix KNPE caused by optimizations in control-flow analysis

The problem is that when performing full analysis we do it in
a backward order while result for trivial vals is filled
in a forward one.

It turns out that reversedInstuctions might return a superset of
forward traversed instructions, e.g. in case of dead code in lambda.

At the same time result for trivial vals is constant
for any instruction, thus we can just return its constant value
and use it in the full analysis

 #KT-20895 Fixed
This commit is contained in:
Denis Zharkov
2017-11-14 11:44:20 +03:00
parent 2a0b937aac
commit 1f9d56439a
5 changed files with 40 additions and 14 deletions
@@ -0,0 +1,11 @@
inline fun myRun(b: () -> Unit) = b()
fun foo() {
var <!UNUSED_VARIABLE!>a<!>: Int
return
<!UNREACHABLE_CODE!>myRun {
return
}<!>
}
@@ -0,0 +1,4 @@
package
public fun foo(): kotlin.Unit
public inline fun myRun(/*0*/ b: () -> kotlin.Unit): kotlin.Unit