From 5d004c06bfa69b4d3229450c9b726dcc0fb012fc Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Thu, 16 Feb 2017 18:16:12 +0300 Subject: [PATCH] default implementation of interface methods support --- .../kotlin/backend/konan/descriptors/ClassVtablesBuilder.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassVtablesBuilder.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassVtablesBuilder.kt index 7c0c581b3be..c066e9fbc8c 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassVtablesBuilder.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/ClassVtablesBuilder.kt @@ -47,13 +47,15 @@ internal class ClassVtablesBuilder(val classDescriptor: ClassDescriptor, val con } else { if (!superMethod.trivialOverride()) newVtableSlots.add(OverriddenFunctionDescriptor(overridingMethod, superMethod.descriptor)) + // Overriding method is defined in the current class and is not inherited - take it as is. newVtableSlots.add(OverriddenFunctionDescriptor(overridingMethod, overridingMethod)) OverriddenFunctionDescriptor(overridingMethod, superMethod.overriddenDescriptor) } } methods.filterNot { method -> inheritedVtableSlots.any { it.descriptor == method } } // Find newly defined methods. - .mapTo(newVtableSlots) { OverriddenFunctionDescriptor(it, it) } + // Select target because method might be taken from default implementation of interface. + .mapTo(newVtableSlots) { OverriddenFunctionDescriptor(it, it.target) } val list = inheritedVtableSlots + newVtableSlots.filter { it.descriptor.isOverridable }.sortedBy { it.overriddenDescriptor.functionName.localHash.value @@ -64,7 +66,7 @@ internal class ClassVtablesBuilder(val classDescriptor: ClassDescriptor, val con fun vtableIndex(function: FunctionDescriptor): Int { val target = function.target val index = vtableEntries.indexOfFirst { it.overriddenDescriptor == target } - if (index < 0) throw Error(function.toString() + " not in vtable of " + this.toString()) + if (index < 0) throw Error(function.toString() + " not in vtable of " + classDescriptor.toString()) return index }