[FIR] Extract LHS receiver of assignment operator statements

#KT-53490 Fixed
This commit is contained in:
Brian Norman
2023-06-30 17:13:05 +03:00
committed by Space Team
parent 14276642d4
commit 10ed26991d
45 changed files with 1894 additions and 124 deletions
@@ -0,0 +1,60 @@
// EXPECTED_REACHABLE_NODES: 1298
package foo
var log = ""
class A(val value: Int) {
operator fun plus(other: A): A {
log += "A.plus(${other.value});"
return A(value + other.value)
}
}
val _array = arrayOf(A(2))
fun getArray(): Array<A> {
log += "getArray();"
return _array
}
fun getArrayIndex(): Int {
log += "getArrayIndex();"
return 0
}
class B(value: Int) {
var a = A(value)
}
val _property = B(10)
val _functionResult = B(100)
val foo: B
get() {
log += "foo;"
return _property
}
fun bar(): B {
log += "bar();"
return _functionResult
}
fun box(): String {
getArray()[getArrayIndex()] += A(3)
assertEquals(5, _array[0].value)
foo.a += A(20)
assertEquals(30, _property.a.value)
bar().a += A(200)
assertEquals(300, _functionResult.a.value)
assertEquals("getArray();getArrayIndex();A.plus(3);foo;A.plus(20);bar();A.plus(200);", log)
return "OK"
}
fun assertEquals(first: Any?, second: Any?) {
if (first != second) throw AssertionError("$first != $second")
}