Files
kotlin-fork/compiler/testData/ir/irText/declarations/contextReceivers/compoundAssignmentOperators.kt
T
Sergej Jaskiewicz 1a29b9efff [FIR, IR] Fix name mangling for functions with context receivers
- Mangled names of property accessors now include context receiver
  types of the corresponding property when computed from FIR.
- Context receivers are now supported when computing mangled names
  from IR
- IrBasedDescriptors now account for context receivers

^KT-57435 Fixed
2023-05-23 08:55:50 +00:00

67 lines
1.4 KiB
Kotlin
Vendored

// !LANGUAGE: +ContextReceivers
// IGNORE_BACKEND: JS_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"
}