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

24 lines
417 B
Kotlin
Vendored

// IGNORE_BACKEND: JVM_IR
import kotlin.reflect.KProperty
class Delegate<T>(val f: (T) -> Int) {
operator fun getValue(t: T, p: KProperty<*>): Int = f(t)
}
val p = Delegate<A> { t -> t.foo() }
class A(val i: Int) {
val prop: Int by p
fun foo(): Int {
return i
}
}
fun box(): String {
if(A(1).prop != 1) return "fail get1"
if(A(10).prop != 10) return "fail get2"
return "OK"
}