Files
kotlin-fork/compiler/testData/codegen/box/callableReference/property/delegated.kt
T
Roman Artemev 0c6256d003 Fix initialization order
* put inheritance code in the beginning
 * put top-level initializer after any declaration
2018-07-24 20:16:39 +03:00

26 lines
514 B
Kotlin
Vendored

// IGNORE_BACKEND: JVM_IR
import kotlin.reflect.KProperty
val four: Int by NumberDecrypter
class A {
val two: Int by NumberDecrypter
}
object NumberDecrypter {
operator fun getValue(instance: Any?, data: KProperty<*>) = when (data.name) {
"four" -> 4
"two" -> 2
else -> throw AssertionError()
}
}
fun box(): String {
val x = ::four.get()
if (x != 4) return "Fail x: $x"
val a = A()
val y = A::two.get(a)
if (y != 2) return "Fail y: $y"
return "OK"
}