diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.kt index 10168b7c88c..15445dfaa38 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/OverrideResolver.kt @@ -586,7 +586,9 @@ class OverrideResolver( if (kind != FAKE_OVERRIDE && kind != DELEGATION) return val directOverridden = descriptor.overriddenDescriptors - assert(!directOverridden.isEmpty()) { kind.toString() + " " + descriptor.name.asString() + " must override something" } + + // directOverridden may be empty if user tries to delegate implementation of abstract class instead of interface + if (directOverridden.isEmpty()) return // collects map from the directly overridden descriptor to the set of declarations: // -- if directly overridden is not fake, the set consists of one element: this directly overridden diff --git a/compiler/testData/diagnostics/tests/delegation/kt40510.fir.kt b/compiler/testData/diagnostics/tests/delegation/kt40510.fir.kt new file mode 100644 index 00000000000..75d72840e0c --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/kt40510.fir.kt @@ -0,0 +1,14 @@ +// ISSUE: KT-40510 + +// FILE: foo/A.java +package foo; + +public abstract class A { + // package-private + abstract void foo(); +} + +// FILE: main.kt +import foo.A + +class DelegatedA(val a: A) : A by a diff --git a/compiler/testData/diagnostics/tests/delegation/kt40510.kt b/compiler/testData/diagnostics/tests/delegation/kt40510.kt new file mode 100644 index 00000000000..ca1dcd07848 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/kt40510.kt @@ -0,0 +1,14 @@ +// ISSUE: KT-40510 + +// FILE: foo/A.java +package foo; + +public abstract class A { + // package-private + abstract void foo(); +} + +// FILE: main.kt +import foo.A + +class DelegatedA(val a: A) : A by a diff --git a/compiler/testData/diagnostics/tests/delegation/kt40510.txt b/compiler/testData/diagnostics/tests/delegation/kt40510.txt new file mode 100644 index 00000000000..94aed60a082 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/kt40510.txt @@ -0,0 +1,22 @@ +package + +public final class DelegatedA : foo.A { + public constructor DelegatedA(/*0*/ a: foo.A) + public final val a: foo.A + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open /*delegation*/ fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +package foo { + + public abstract class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public/*package*/ abstract fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 6e09f40619a..fbb0cacf8f4 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -7389,6 +7389,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/delegation/Delegation_ScopeInitializationOrder.kt"); } + @Test + @TestMetadata("kt40510.kt") + public void testKt40510() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegation/kt40510.kt"); + } + @Test @TestMetadata("kt8154.kt") public void testKt8154() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 2df1ed4ac7a..5e40236383c 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -7383,6 +7383,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/delegation/Delegation_ScopeInitializationOrder.kt"); } + @Test + @TestMetadata("kt40510.kt") + public void testKt40510() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegation/kt40510.kt"); + } + @Test @TestMetadata("kt8154.kt") public void testKt8154() throws Exception {