Files
kotlin-fork/compiler/testData/codegen/box/extensionFunctions/contextReceivers/arrayAccessOperators.kt
T
2021-12-09 13:26:37 +03:00

25 lines
599 B
Kotlin
Vendored

// !LANGUAGE: +ContextReceivers
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
// FIR status: context receivers aren't yet supported
data class MyContainer(var s: String)
context(Int)
operator fun MyContainer.get(index: Int): String? {
return if (index == 0 && this@Int == 42) s else null
}
context(Int)
operator fun MyContainer.set(index: Int, value: String) {
if (index != 0 || this@Int != 42) return
s = value
}
fun box(): String {
return with(42) {
val myContainer = MyContainer("fail")
myContainer[0] = "OK"
myContainer[0] ?: "fail"
}
}