Files
kotlin-fork/compiler/testData/codegen/box/reflection/properties/getDelegate/nameClashClassAndCompanion.kt
T
2020-06-02 12:00:52 +03: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"
}