Files
kotlin/compiler/testData/codegen/box/reflection/mapping/methodsFromObject.kt
Alexander Udalov 4c9e9b1f3a Fix KotlinReflectionInternalError on encountering 'clone' in a class
`RuntimeTypeMapper.mapSignature` threw exception because the descriptor
for `clone` was created manually in CloneableClassScope and therefore it
didn't have a JVM signature as in deserialized descriptors, and wasn't
recognized as a Java method either.

 #KT-22923 Fixed
2019-05-31 12:29:20 +02:00

37 lines
1001 B
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_REFLECT
import kotlin.reflect.KClass
import kotlin.reflect.full.memberFunctions
import kotlin.reflect.jvm.javaMethod
import kotlin.test.assertEquals
annotation class A
interface I
class C
interface MyCustomMembers {
fun equals(): Boolean
fun hashCode(hehe: Int): Int
fun toString(hehe: String): Any
}
interface MyCloneable : Cloneable
fun KClass<*>.functions() = memberFunctions.map { it.javaMethod!!.name }.sorted()
fun box(): String {
assertEquals(listOf("equals", "hashCode", "toString"), A::class.functions())
assertEquals(listOf("equals", "hashCode", "toString"), I::class.functions())
assertEquals(listOf("equals", "hashCode", "toString"), C::class.functions())
assertEquals(
listOf("equals", "equals", "hashCode", "hashCode", "toString", "toString"),
MyCustomMembers::class.functions()
)
assertEquals(listOf("clone", "equals", "hashCode", "toString"), MyCloneable::class.functions())
return "OK"
}