Files
kotlin-fork/compiler/testData/codegen/box/toArray/toArray.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

24 lines
681 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_RUNTIME
class MyCollection<T>(val delegate: Collection<T>): Collection<T> by delegate
fun box(): String {
val collection = MyCollection(listOf(2, 3, 9)) as java.util.Collection<*>
val array1 = collection.toArray()
val array2 = collection.toArray(arrayOfNulls<Int>(3) as Array<Int>)
if (!array1.isArrayOf<Any>()) return (array1 as Object).getClass().toString()
if (!array2.isArrayOf<Int>()) return (array2 as Object).getClass().toString()
val s1 = array1.contentToString()
val s2 = array2.contentToString()
if (s1 != "[2, 3, 9]") return "s1 = $s1"
if (s2 != "[2, 3, 9]") return "s2 = $s2"
return "OK"
}