Files
kotlin-fork/compiler/testData/codegen/box/reflection/properties/getDelegate/nameClashClassAndCompanion.kt
T
Alexander Udalov 78f2515e95 Introduce KProperty{0,1,2}.getDelegate
#KT-8384 In Progress
2017-01-23 12:25:35 +03:00

27 lines
751 B
Kotlin
Vendored

// IGNORE_BACKEND: JS
// 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"
}