Provide equals/hashCode/toString for KType implementation
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
fun unit(p: Unit): Unit {}
|
||||
|
||||
fun nullable(s: String): String? = s
|
||||
|
||||
class A {
|
||||
fun <T> typeParam(t: T): T = t
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
fun check(t1: KType, t2: KType) {
|
||||
assertEquals(t1, t2)
|
||||
assertEquals(t1.hashCode(), t2.hashCode())
|
||||
}
|
||||
|
||||
check(::unit.parameters.single().type, ::unit.returnType)
|
||||
|
||||
assertNotEquals(::nullable.parameters.single().type, ::nullable.returnType)
|
||||
|
||||
val typeParam = A::class.members.single { it.name == "typeParam" }
|
||||
check(typeParam.parameters.last().type, typeParam.returnType)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun String?.foo(x: Int, y: Array<Int>, z: IntArray, w: List<Map<Any, A<*>>>) {}
|
||||
|
||||
class A<T> {
|
||||
fun <U> bar(t: T, u: U): T? = null
|
||||
}
|
||||
|
||||
fun baz(inProjection: A<in Number>, outProjection: A<out Number>) {}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(
|
||||
listOf(
|
||||
"kotlin.String?",
|
||||
"kotlin.Int",
|
||||
"kotlin.Array<kotlin.Int>",
|
||||
"kotlin.IntArray",
|
||||
"kotlin.List<kotlin.Map<kotlin.Any, A<*>>>"
|
||||
),
|
||||
String?::foo.parameters.map { it.type.toString() }
|
||||
)
|
||||
|
||||
assertEquals("kotlin.Unit", String?::foo.returnType.toString())
|
||||
|
||||
val bar = A::class.members.single { it.name == "bar" }
|
||||
assertEquals(listOf("A<T>", "T", "U"), bar.parameters.map { it.type.toString() })
|
||||
assertEquals("T?", bar.returnType.toString())
|
||||
|
||||
assertEquals(
|
||||
listOf("A<in kotlin.Number>", "A<out kotlin.Number>"),
|
||||
::baz.parameters.map { it.type.toString() }
|
||||
)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user