Files
kotlin-fork/compiler/testData/codegen/box/fieldRename/delegates.kt
T
2018-06-28 12:26:41 +02:00

31 lines
676 B
Kotlin
Vendored

// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND: JS_IR
import kotlin.reflect.KProperty
public open class TestDelegate<T: Any>(private val initializer: () -> T) {
private var value: T? = null
operator open fun getValue(thisRef: Any?, desc: KProperty<*>): T {
if (value == null) {
value = initializer()
}
return value!!
}
operator open fun setValue(thisRef: Any?, desc: KProperty<*>, svalue : T) {
value = svalue
}
}
class A {}
class B {}
public val A.s: String by TestDelegate( {"OK2"})
public val B.s: String by TestDelegate( {"OK"})
fun box() : String {
if (A().s != "OK2") return "fail1"
return B().s
}