[PSI2IR] Generate safe calls correctly

This commit is contained in:
Anastasiya Shadrina
2021-11-18 00:53:53 +07:00
committed by TeamCityServer
parent 229a009828
commit a760865767
6 changed files with 68 additions and 3 deletions
@@ -0,0 +1,33 @@
// !LANGUAGE: +ContextReceivers
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
class LoggingCounter {
var operationCounter = 0
}
class A {
context(LoggingCounter)
var p: Int
get(): Int {
operationCounter++
return 1
}
set(value: Int) {
operationCounter++
}
}
fun foo() = A()
fun box(): String {
val loggingCounter = LoggingCounter()
with(loggingCounter) {
foo().p += 1
foo().p = 1
foo()?.p = 1
foo().p
}
val operationsTotal = loggingCounter.operationCounter
return if (operationsTotal == 5) "OK" else "$operationsTotal"
}