[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,45 @@
// !LANGUAGE: +ContextReceivers
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
data class Result(val i: Int)
var operationScore = 0
context(Int)
operator fun Result.unaryMinus(): Result {
operationScore += this@Int
return Result(-i)
}
context(Int)
operator fun Result.unaryPlus(): Result {
operationScore += this@Int
return Result(if (i < 0) (-i) else i)
}
context(Int)
operator fun Result.inc(): Result {
operationScore += this@Int
return Result(i + 1)
}
context(Int)
operator fun Result.dec(): Result {
operationScore += this@Int
return Result(i - 1)
}
fun box(): String {
var result = Result(0)
with(1) {
result++
result++
(-result)
+result
result--
}
return if (result.i == 1 && operationScore == 5) "OK" else "fail"
}