Files
kotlin-fork/compiler/testData/ir/irText/declarations/contextReceivers/delegatedPropertiesOperators.kt
T
Sergej Jaskiewicz f2031ae642 [IR] Don't print multifile/synthetic facade class names in irText tests
This only applies to JVM and fq-names in declaration references
in IR dumps.

This enables us to run more irText tests on platforms other than JVM
(see KT-58605).
2023-06-05 10:40:17 +00:00

35 lines
724 B
Kotlin
Vendored

// !LANGUAGE: +ContextReceivers
// WITH_STDLIB
import kotlin.reflect.KProperty
var operationScore = 0
class Delegate {
var delegateValue = "fail"
context(Int)
operator fun getValue(thisRef: Any?, property: KProperty<*>): String {
operationScore += this@Int
return delegateValue
}
context(Int)
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
operationScore += this@Int
delegateValue = value
}
}
context(Int)
class Result {
var s: String by Delegate()
}
fun box(): String {
val result = with(1) { Result() }
result.s = "OK"
val returnValue = result.s
return if (operationScore == 2) returnValue else "fail"
}