[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,67 @@
// !LANGUAGE: +ContextReceivers
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
data class Result(var i: Int)
var operationScore = 0
context(Int)
operator fun Result.plus(other: Result): Result {
operationScore += this@Int
return Result(i + other.i)
}
context(Int)
operator fun Result.plusAssign(other: Result) {
operationScore += this@Int
i += other.i
}
context(Int)
operator fun Result.minus(other: Result): Result {
operationScore += this@Int
return Result(i - other.i)
}
context(Int)
operator fun Result.minusAssign(other: Result) {
operationScore += this@Int
i -= other.i
}
context(Int)
operator fun Result.times(other: Result): Result {
operationScore += this@Int
return Result(i * other.i)
}
context(Int)
operator fun Result.timesAssign(other: Result) {
operationScore += this@Int
i *= other.i
}
context(Int)
operator fun Result.div(other: Result): Result {
operationScore += this@Int
return Result(i / other.i)
}
context(Int)
operator fun Result.divAssign(other: Result) {
operationScore += this@Int
i /= other.i
}
fun box(): String {
val result = Result(0)
with(1) {
result += (Result(1) + Result(1))
result -= (Result(1) - Result(0))
result *= (Result(1) * Result(2))
result /= (Result(4) / Result(2))
}
return if (result.i == 1 && operationScore == 8) "OK" else "fail"
}