Make KClasses for primitives equal to KClasses for wrapper types

Both primitive int and wrapper type java.lang.Integer are represented by the
single type kotlin.Int in Kotlin, so inequality between the corresponding
KClasses was confusing here. To keep the old behavior, one may call 'k1.java ==
k2.java' instead of `k1 == k2`

 #KT-13462 Fixed
This commit is contained in:
Alexander Udalov
2016-08-09 15:42:42 +03:00
parent 3efa738bc0
commit 5b1ee13db8
7 changed files with 53 additions and 16 deletions
@@ -0,0 +1,15 @@
// WITH_REFLECT
import kotlin.test.assertEquals
import kotlin.test.assertFalse
fun box(): String {
val x = Int::class.javaPrimitiveType!!.kotlin
val y = Int::class.javaObjectType.kotlin
assertEquals(x, y)
assertEquals(x.hashCode(), y.hashCode())
assertFalse(x === y)
return "OK"
}
@@ -11,10 +11,9 @@ fun box(): String {
assertTrue(primitiveInt.isSubclassOf(primitiveInt))
assertTrue(wrapperInt.isSubclassOf(wrapperInt))
// Currently KClass for int != KClass for java.lang.Integer, thus they are not a subclass of each other either
// TODO: reconsider this decision
assertFalse(primitiveInt.isSubclassOf(wrapperInt))
assertFalse(wrapperInt.isSubclassOf(primitiveInt))
// KClass for int equals KClass for java.lang.Integer, so they are also a subclass of each other
assertTrue(primitiveInt.isSubclassOf(wrapperInt))
assertTrue(wrapperInt.isSubclassOf(primitiveInt))
return "OK"
}