Files
kotlin-fork/compiler/testData/codegen/box/reflection/properties/getDelegate/nameClashClassAndCompanion.kt
T
Alexander Udalov 6cc293a0c5 JVM IR: record FIELD_FOR_PROPERTY for property delegates
Delegated properties now have their $delegate fields recorded in the
metadata (in `ClassCodegen.generateField`). This part of metadata is
used by `KPropertyN.getDelegate` functions, so almost all tests on
getDelegate are now unmuted
2019-04-30 13:15:29 +02:00

27 lines
752 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.reflect.KProperty
import kotlin.reflect.jvm.isAccessible
import kotlin.test.*
class Delegate(val value: String) {
operator fun getValue(instance: Any?, property: KProperty<*>) = value
}
class Foo {
val x: String by Delegate("class")
companion object {
val x: String by Delegate("companion")
}
}
fun box(): String {
val foo = Foo()
assertEquals("class", ((foo::x).apply { isAccessible = true }.getDelegate() as Delegate).value)
assertEquals("class", ((Foo::x).apply { isAccessible = true }.getDelegate(foo) as Delegate).value)
assertEquals("companion", ((Foo.Companion::x).apply { isAccessible = true }.getDelegate() as Delegate).value)
return "OK"
}