[Tests] Make sure desugaring works with context receivers

This commit is contained in:
Anastasiya Shadrina
2021-11-17 17:39:49 +07:00
committed by TeamCityServer
parent 0bfea4fc52
commit 4d0eb74d79
29 changed files with 2740 additions and 0 deletions
@@ -0,0 +1,36 @@
// !LANGUAGE: +ContextReceivers
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
// 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"
}