JVM IR: change generation scheme of property $delegate methods

Generate $delegate method as instance method in
PropertyReferenceDelegationLowering, and remove dispatch receiver later
in MakePropertyDelegateMethodsStatic. The method needs to be static to
be non-overridable (see delegateMethodIsNonOverridable.kt), and public
to be accessible in reflection.

Otherwise we generated incorrect IR where a static function accessed an
instance field of the containing class, which failed in multiple places
including LocalDeclarationsLowering.

 #KT-48350 Fixed
This commit is contained in:
Alexander Udalov
2021-08-21 02:38:11 +02:00
committed by Alexander Udalov
parent 50508da156
commit 04c5bbdcf8
25 changed files with 565 additions and 48 deletions
@@ -0,0 +1,25 @@
// WITH_RUNTIME
interface I {
var z: String
}
class X {
var p: String = "Fail"
}
class A {
val x = X()
inner class Y : I {
override var z: String by x::p
}
val y = Y()
}
fun box(): String {
val a = A()
a.y.z = "OK"
return a.y.z
}