Files
kotlin-fork/compiler/testData/codegen/box/closures/kt11634_4.kt
T
Juan Chen d163853c97 [FIR] add support for implementation by delgation
This commit handles "subclass: super-interface by delegate-expression".

During Psi2Fir, for each delegate, we add to the subclass a synthetic
field (which has type super-interface), and an assignment of the
delegate-expression to the synthetic field in the primary constructor,
so that the delegate-expression can be resolved and transformed along
the way.

During Fir2Ir, we look up delegatable members from the super-interface
and generate corresponding functions/properties for the subclass.

TODO: support for generic delegatable members and generic
super-interface.
2020-07-08 09:42:24 +03:00

28 lines
528 B
Kotlin
Vendored

interface A {
fun foo(): String
}
open class Base (val p: String) {
open val a = object : A {
override fun foo(): String {
return p
}
}
}
open class Derived1 (p: String): Base(p) {
override open val a = object : A {
override fun foo(): String {
return "fail"
}
}
inner class Derived2(p: String) : Base(p) {
val x = object : A by super<Base>@Derived1.a {}
}
}
fun box(): String {
return Derived1("OK").Derived2("fail").x.foo()
}