cd9f59325e
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
72 lines
1.4 KiB
Kotlin
Vendored
72 lines
1.4 KiB
Kotlin
Vendored
|
|
// 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"
|
|
} |