From fbf4db6428939182e48f19c5180a0ce38d30309b Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Thu, 1 Dec 2016 15:08:08 +0300 Subject: [PATCH] Fix RTTI bugs. (#105) --- .../jetbrains/kotlin/backend/konan/DescriptorUtils.kt | 9 +++++++-- .../jetbrains/kotlin/backend/konan/llvm/RTTIGenerator.kt | 6 +++--- runtime/src/main/kotlin/kotlin/collections/ArrayList.kt | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/DescriptorUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/DescriptorUtils.kt index ce6b3830184..37497d52437 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/DescriptorUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/DescriptorUtils.kt @@ -10,7 +10,11 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.* internal val ClassDescriptor.implementedInterfaces: List get() { val superClassImplementedInterfaces = this.getSuperClassNotAny()?.implementedInterfaces ?: emptyList() - return (superClassImplementedInterfaces + this.getSuperInterfaces()).distinctBy { it.classId } + val superInterfaces = this.getSuperInterfaces() + val superInterfacesImplementedInterfaces = superInterfaces.flatMap { it.implementedInterfaces } + return (superClassImplementedInterfaces + + superInterfacesImplementedInterfaces + + superInterfaces).distinctBy { it.classId } } @@ -62,6 +66,7 @@ internal val ClassDescriptor.isArray: Boolean internal val ClassDescriptor.isInterface: Boolean get() = (this.kind == ClassKind.INTERFACE) + internal val CallableDescriptor.allValueParameters: List get() { val constructorReceiver = if (this is ConstructorDescriptor) { @@ -76,4 +81,4 @@ internal val CallableDescriptor.allValueParameters: List this.extensionReceiverParameter).filterNotNull() return receivers + this.valueParameters - } \ No newline at end of file + } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/RTTIGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/RTTIGenerator.kt index 3ded8146712..a7d0a3398f1 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/RTTIGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/RTTIGenerator.kt @@ -149,9 +149,9 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils { val size = getInstanceSize(classType, className) - val superTypeOrNull = classDesc.getSuperClassNotAny() - val superType = if (superTypeOrNull != null) superTypeOrNull.llvmTypeInfoPtr - else NullPointer(runtime.typeInfoType) + val superTypeOrAny = classDesc.getSuperClassOrAny() + val superType = if (KotlinBuiltIns.isAny(classDesc)) NullPointer(runtime.typeInfoType) + else superTypeOrAny.llvmTypeInfoPtr val interfaces = classDesc.implementedInterfaces.map { it.llvmTypeInfoPtr } val interfacesPtr = staticData.placeGlobalConstArray("kintf:$className", diff --git a/runtime/src/main/kotlin/kotlin/collections/ArrayList.kt b/runtime/src/main/kotlin/kotlin/collections/ArrayList.kt index af554fd91bd..179db5637e1 100644 --- a/runtime/src/main/kotlin/kotlin/collections/ArrayList.kt +++ b/runtime/src/main/kotlin/kotlin/collections/ArrayList.kt @@ -151,7 +151,7 @@ class ArrayList private constructor( override fun equals(other: Any?): Boolean { //TODO: rethink instance checks, shall it be other is List<*>? return other === this || - (other is ArrayList<*>) && contentEquals(other) + (other is List<*>) && contentEquals(other) } override fun hashCode(): Int {