Files
kotlin-fork/compiler/testData/codegen/box/safeCall/augmentedAssigmentPlus.kt
T
Ilya Chernikov 5b3816cce5 Test infra: refactor IGNORE_BACKEND directive
treat it as a general one, introduce *_K1 and *_K2 variants for
more specific ignoring
2022-11-12 16:28:23 +01:00

57 lines
863 B
Kotlin
Vendored

// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
var cnt = 0
class A
var A?.b: A?
get() {
return this
}
set(v) {
cnt++
}
var A?.c: A?
get() {
return this
}
set(v) {
cnt++
}
operator fun A?.get(i: Int): A? = this
operator fun A?.set(i: Int, v: A?): A? {
cnt++
return this
}
operator fun A?.plus(a: A?) = this
fun test(a: A?) {
a?.b += null
a?.b?.c += null
a?.b.c += null // ".c" will be called anyway
a?.b[0] += null
a?.b?.c[0] += null
a?.b.c[0] += null // ".c" will be called anyway
a?.b[0][0] += null
a?.b?.c[0][0] += null
a?.b.c[0][0] += null // ".c" will be called anyway
}
fun box(): String {
test(null)
if (cnt != 3) return "fail 1: $cnt"
cnt = 0
test(A())
if (cnt != 9) return "fail 2: $cnt"
return "OK"
}