[KLIB] Fix deserialization of anonymous classes

In case of initializing property or function with anonymous object the
object is being exposed outside its field/function's scope and
accessible on previous level. In this case in `declarations only` mode
we have unbound symbols. Fix is to force body/initializer loading in
such cases.

Make sure it is deserialized in `declarations'only` mode too.

 - Fix KT-40216
 - Add test
This commit is contained in:
Roman Artemev
2020-07-14 16:41:27 +03:00
committed by romanart
parent d31de6c8de
commit cd9f59325e
9 changed files with 166 additions and 15 deletions
+72
View File
@@ -0,0 +1,72 @@
// MODULE: lib
// FILE: lib.kt
// KT-40216
inline fun <T> T.also(f: (T) -> Unit): T {
f(this)
return this
}
object FieldTest {
var result = ""
private val test = object {
fun bar() = object {
fun qux() = object {
fun biq() = object {
fun caz() = object {
}.also { result += "d" }
}.also { result += "c" }
}.also { result += "b" }
}.also { result += "a" }
}.also { result += "!" }
private val ttt = test.bar()
private val qqq = ttt.qux()
val bbb = qqq.biq().also { it.caz() }
}
object FunTest {
var result = ""
private fun bar() = object {
fun qux() = object {
fun biq() = object {
fun caz() = object {
}.also { result += "w" }
}.also { result += "x" }
}.also { result += "y" }
}.also { result += "z" }
private fun ttt() = bar()
private fun qqq() = ttt().qux()
fun bbb() = qqq().biq().also { it.caz() }
}
// MODULE: lib2(lib)
// FILE: lib2.kt
fun test1(): String {
return FieldTest.result
}
fun test2(): String {
FunTest.bbb()
return FunTest.result
}
// MODULE: main(lib2)
// FILE: main.kt
fun box(): String {
if (test1() != "!abcd") return "FAIL 1: ${test1()}"
if (test2() != "zyxw") return "FAIL 2: ${test2()}"
return "OK"
}