[FE] Don't throw assertion in OverrideResolver if directOverridden is empty
Those descriptors may be empty in case user made a mistake and tried to delegate implementation of abstract class instead of interface (and we don't add functions from abstract class to overriden descriptors of fake overrides in case of delegation by) #KT-40510 Fixed
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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) : <!DELEGATION_NOT_TO_INTERFACE!>A<!> by a
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+6
@@ -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 {
|
||||
|
||||
+6
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user