IR: use parameters for captures in field/instance initializers

val y = 1
    object { val x = y }
  ->
    class XKt$1(`$y`: Int) { val x: Int = `$y` }

Note that `$y` is not stored in a field because it's not used outside
the primary constructor.

One exception is captured inline parameters on the JVM backend, as the
bytecode inliner uses field assignment instructions (setfield) to locate
them; removing the field is thus not possible.
This commit is contained in:
pyos
2021-09-16 13:14:27 +02:00
committed by Alexander Udalov
parent 85c53bc24e
commit e1520c61da
4 changed files with 84 additions and 24 deletions
@@ -2,8 +2,8 @@ open class Base(parameter: String)
fun foo(captured: String) {
object : Base(captured) {
// val x = captured
// init { println(captured) }
val x = captured
init { println(captured) }
}
}