JVM_IR: optimize out redundant delegated property receiver fields

Now this:

    class C {
        val x = something
        val y by x::property
    }

is *exactly* the same as this:

    class C {
        val x = something
        val y get() = x.property
    }

(plus a `getY$delegate` method)
This commit is contained in:
pyos
2021-07-02 12:35:02 +02:00
committed by Alexander Udalov
parent 2fe7cf27ad
commit d988853c11
11 changed files with 175 additions and 17 deletions
@@ -0,0 +1,16 @@
// WITH_RUNTIME
var result = "Fail"
object O {
val z = 42
init { result = "OK" }
}
class A {
val x by O::z
}
fun box(): String {
A()
return result
}
@@ -0,0 +1,23 @@
// WITH_RUNTIME
val String.foo: String
get() = this
abstract class A {
abstract val x: String
val y by x::foo
}
var storage = "OK"
class B : A() {
override var x: String
get() = storage
set(value) { storage = value }
}
fun box(): String {
val b = B()
b.x = "fail"
return b.y
}