[Tests] Make sure desugaring works with context receivers
This commit is contained in:
committed by
TeamCityServer
parent
0bfea4fc52
commit
4d0eb74d79
Vendored
+67
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user