diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt index fabd169b0c6..47621613eda 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/descriptors/DescriptorUtils.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertySetterDescriptorImpl import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.OverridingUtil import org.jetbrains.kotlin.resolve.descriptorUtil.* import org.jetbrains.kotlin.resolve.scopes.MemberScope @@ -210,8 +211,11 @@ fun ClassDescriptor.vtableIndex(function: FunctionDescriptor): Int { val ClassDescriptor.methodTableEntries: List get() { - assert (!this.isAbstract()) - - return this.contributedMethods.filter { it.isOverridableOrOverrides } + assert(!this.isAbstract()) + return this.contributedMethods.filter { + // We check that either method is open, or one of declarations it overrides + // is open. + it.isOverridable || DescriptorUtils.getAllOverriddenDeclarations(it).any { it.isOverridable } + } // TODO: probably method table should contain all accessible methods to improve binary compatibility } \ No newline at end of file diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 71ef4b7d02d..cc5d5744c31 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -653,6 +653,11 @@ task catch7(type: RunKonanTest) { source = "runtime/exceptions/catch7.kt" } +task extend_exception(type: RunKonanTest) { + goldValue = "OK\n" + source = "runtime/exceptions/extend0.kt" +} + task catch3(type: RunKonanTest) { goldValue = "Before\nCaught Throwable\nDone\n" source = "codegen/try/catch3.kt" diff --git a/backend.native/tests/runtime/exceptions/extend0.kt b/backend.native/tests/runtime/exceptions/extend0.kt new file mode 100644 index 00000000000..071a53363ff --- /dev/null +++ b/backend.native/tests/runtime/exceptions/extend0.kt @@ -0,0 +1,9 @@ +class C : Exception("OK") + +fun main(args: Array) { + try { + throw C() + } catch (e: Throwable) { + println(e.message!!) + } +} \ No newline at end of file