[K/N] Force static constants and boxing caches be same values

^KT-49403
This commit is contained in:
Pavel Kunyavskiy
2021-10-22 18:45:02 +03:00
committed by Space
parent 2adf19c2bb
commit f4a88bde4e
4 changed files with 90 additions and 22 deletions
@@ -172,4 +172,36 @@ inline fun invokeAndReturnKClass(block: ()->Boolean) : KClass<*> {
assertTrue(clazz.isPermanent())
assertEquals("kotlin.Int", clazz.qualifiedName)
}
}
@Test fun testSmallIntIdentity() {
val xBool = true
val xBoolStatic : Any = false
val xBoolDyanmic : Any = !xBool
assertSame(xBoolStatic, xBoolDyanmic)
val xByte = 1.toByte()
val xByteStatic : Any = 2.toByte()
val xByteDyanmic : Any = (xByte + xByte).toByte()
assertSame(xByteStatic, xByteDyanmic)
val xShort = 1.toShort()
val xShortStatic : Any = 2.toShort()
val xShortDyanmic : Any = (xShort + xShort).toShort()
assertSame(xShortStatic, xShortDyanmic)
val xInt = 1.toInt()
val xIntStatic : Any = 2.toInt()
val xIntDyanmic : Any = xInt + xInt
assertSame(xIntStatic, xIntDyanmic)
val xChar = 1.toChar()
val xCharStatic : Any = 2.toChar()
val xCharDyanmic : Any = (xChar.code + xChar.code).toChar()
assertSame(xCharStatic, xCharDyanmic)
val xLong = 1.toLong()
val xLongStatic = 2.toLong()
val xLongDyanmic = xLong + xLong
assertSame(xLongStatic, xLongDyanmic)
}