JVM_IR KT-42758 don't use 'this' for object self-reference by name

This commit is contained in:
Dmitry Petrov
2020-11-19 12:51:03 +03:00
parent 118a7d4e34
commit e17158d961
11 changed files with 203 additions and 7 deletions
+23
View File
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// FULL_JDK
// WITH_RUNTIME
import java.io.*
object Thing : Serializable {
private fun readResolve(): Any = Thing
}
private inline fun <reified T : Serializable> roundTrip(value: T): T {
val outputStream = ByteArrayOutputStream()
ObjectOutputStream(outputStream).use { it.writeObject(value) }
val inputStream = ByteArrayInputStream(outputStream.toByteArray())
return ObjectInputStream(inputStream).use { it.readObject() } as T
}
fun box(): String {
if (Thing !== roundTrip(Thing))
throw Exception("Thing !== roundTrip(Thing)")
return "OK"
}