Add kotlin.Any to KClass.superclasses if it's absent
#KT-18476 Fixed
This commit is contained in:
+1
-1
@@ -34,7 +34,7 @@ fun box(): String {
|
|||||||
check<Any>()
|
check<Any>()
|
||||||
checkAll<Any>()
|
checkAll<Any>()
|
||||||
|
|
||||||
check<String>(::comparableOfString, ::charSequence, ::serializable)
|
check<String>(::comparableOfString, ::charSequence, ::serializable, ::any)
|
||||||
checkAll<String>(::comparableOfString, ::charSequence, ::serializable, ::any)
|
checkAll<String>(::comparableOfString, ::charSequence, ::serializable, ::any)
|
||||||
|
|
||||||
check<Int>(::number, ::comparableOfInt, ::serializable)
|
check<Int>(::number, ::comparableOfInt, ::serializable)
|
||||||
|
|||||||
@@ -13,10 +13,15 @@ interface Interface
|
|||||||
interface Interface2
|
interface Interface2
|
||||||
class ClassAndTwoInterfaces : Interface, Simple(), Interface2
|
class ClassAndTwoInterfaces : Interface, Simple(), Interface2
|
||||||
|
|
||||||
|
class ClassWithSuperInterfaceOnly : Interface
|
||||||
|
|
||||||
|
annotation class AnnotationClass
|
||||||
|
|
||||||
fun any(): Any = null!!
|
fun any(): Any = null!!
|
||||||
fun simple(): Simple = null!!
|
fun simple(): Simple = null!!
|
||||||
fun interface_(): Interface = null!!
|
fun interface_(): Interface = null!!
|
||||||
fun interface2(): Interface2 = null!!
|
fun interface2(): Interface2 = null!!
|
||||||
|
fun annotation(): Annotation = null!!
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
with(Simple::class) {
|
with(Simple::class) {
|
||||||
@@ -48,5 +53,19 @@ fun box(): String {
|
|||||||
assertEquals(setOf(Interface::class, Simple::class, Interface2::class, Any::class), allSuperclasses.toSet())
|
assertEquals(setOf(Interface::class, Simple::class, Interface2::class, Any::class), allSuperclasses.toSet())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
with (ClassWithSuperInterfaceOnly::class) {
|
||||||
|
assertEquals(listOf(::interface_.returnType, ::any.returnType), supertypes)
|
||||||
|
assertEquals(listOf(Interface::class, Any::class), superclasses)
|
||||||
|
assertEquals(setOf(::interface_.returnType, ::any.returnType), allSupertypes.toSet())
|
||||||
|
assertEquals(setOf(Interface::class, Any::class), allSuperclasses.toSet())
|
||||||
|
}
|
||||||
|
|
||||||
|
with (AnnotationClass::class) {
|
||||||
|
assertEquals(listOf(::annotation.returnType, ::any.returnType), supertypes)
|
||||||
|
assertEquals(listOf(Annotation::class, Any::class), superclasses)
|
||||||
|
assertEquals(listOf(::annotation.returnType, ::any.returnType), allSupertypes)
|
||||||
|
assertEquals(listOf(Annotation::class, Any::class), allSuperclasses)
|
||||||
|
}
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package kotlin.reflect.jvm.internal
|
package kotlin.reflect.jvm.internal
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.CompanionObjectMapping
|
import org.jetbrains.kotlin.builtins.CompanionObjectMapping
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
@@ -27,7 +28,9 @@ import org.jetbrains.kotlin.load.kotlin.reflect.ReflectKotlinClass
|
|||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
|
import org.jetbrains.kotlin.utils.compactIfPossible
|
||||||
import kotlin.jvm.internal.TypeIntrinsics
|
import kotlin.jvm.internal.TypeIntrinsics
|
||||||
import kotlin.reflect.*
|
import kotlin.reflect.*
|
||||||
import kotlin.reflect.jvm.internal.KDeclarationContainerImpl.MemberBelonginess.DECLARED
|
import kotlin.reflect.jvm.internal.KDeclarationContainerImpl.MemberBelonginess.DECLARED
|
||||||
@@ -113,7 +116,9 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) : KDeclaration
|
|||||||
}
|
}
|
||||||
|
|
||||||
val supertypes: List<KType> by ReflectProperties.lazySoft {
|
val supertypes: List<KType> by ReflectProperties.lazySoft {
|
||||||
descriptor.typeConstructor.supertypes.map { kotlinType ->
|
val kotlinTypes = descriptor.typeConstructor.supertypes
|
||||||
|
val result = ArrayList<KTypeImpl>(kotlinTypes.size)
|
||||||
|
kotlinTypes.mapTo(result) { kotlinType ->
|
||||||
KTypeImpl(kotlinType) {
|
KTypeImpl(kotlinType) {
|
||||||
val superClass = kotlinType.constructor.declarationDescriptor
|
val superClass = kotlinType.constructor.declarationDescriptor
|
||||||
if (superClass !is ClassDescriptor) throw KotlinReflectionInternalError("Supertype not a class: $superClass")
|
if (superClass !is ClassDescriptor) throw KotlinReflectionInternalError("Supertype not a class: $superClass")
|
||||||
@@ -131,6 +136,13 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) : KDeclaration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!KotlinBuiltIns.isSpecialClassWithNoSupertypes(descriptor) && result.all {
|
||||||
|
val classKind = DescriptorUtils.getClassDescriptorForType(it.type).kind
|
||||||
|
classKind == ClassKind.INTERFACE || classKind == ClassKind.ANNOTATION_CLASS
|
||||||
|
}) {
|
||||||
|
result += KTypeImpl(descriptor.builtIns.anyType) { Any::class.java }
|
||||||
|
}
|
||||||
|
result.compactIfPossible()
|
||||||
}
|
}
|
||||||
|
|
||||||
val declaredNonStaticMembers: Collection<KCallableImpl<*>>
|
val declaredNonStaticMembers: Collection<KCallableImpl<*>>
|
||||||
|
|||||||
Reference in New Issue
Block a user