Files
kotlin-fork/compiler/testData/ir/irText/declarations/contextReceivers/delegatedPropertiesOperators.kt
T
Sergej Jaskiewicz 973adb6a38 [test] Remove TARGET_BACKEND: JVM_IR for non JVM-specific irText tests
If they fail on other backends, use the IGNORE_BACKEND directive instead
2023-05-16 18:28:23 +00:00

39 lines
801 B
Kotlin
Vendored

// !LANGUAGE: +ContextReceivers
// IGNORE_BACKEND: JS_IR
// WITH_STDLIB
// MUTE_SIGNATURE_COMPARISON_K2: ANY
// ^ KT-57435
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"
}