K1: report ABSTRACT_SUPER_CALL(_WARNING) also for 2+ steps to intersection

#KT-53953 Fixed
This commit is contained in:
Mikhail Glukhikh
2022-09-15 09:42:22 +02:00
committed by Space
parent 3e5d5bcaa7
commit c4a48927d2
4 changed files with 50 additions and 26 deletions
@@ -804,15 +804,7 @@ internal object CheckSuperExpressionCallPart : ResolutionPart() {
if (callComponents.statelessCallbacks.isSuperExpression(resolvedCall.dispatchReceiverArgument)) {
if (candidateDescriptor is CallableMemberDescriptor) {
if (candidateDescriptor.modality == Modality.ABSTRACT) {
addDiagnostic(AbstractSuperCall(resolvedCall.dispatchReceiverArgument!!))
} else if (candidateDescriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE &&
candidateDescriptor.overriddenDescriptors.size > 1
) {
if (candidateDescriptor.overriddenDescriptors.firstOrNull { !it.isInsideInterface }?.modality == Modality.ABSTRACT) {
addDiagnostic(AbstractFakeOverrideSuperCall)
}
}
checkSuperCandidateDescriptor(candidateDescriptor)
}
}
@@ -821,6 +813,28 @@ internal object CheckSuperExpressionCallPart : ResolutionPart() {
addDiagnostic(SuperAsExtensionReceiver(extensionReceiver))
}
}
private fun ResolutionCandidate.checkSuperCandidateDescriptor(candidateDescriptor: CallableMemberDescriptor) {
if (candidateDescriptor.modality == Modality.ABSTRACT) {
addDiagnostic(AbstractSuperCall(resolvedCall.dispatchReceiverArgument!!))
} else if (candidateDescriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
var intersectionFakeOverrideDescriptor = candidateDescriptor
while (intersectionFakeOverrideDescriptor.overriddenDescriptors.size == 1) {
intersectionFakeOverrideDescriptor = intersectionFakeOverrideDescriptor.overriddenDescriptors.first()
if (intersectionFakeOverrideDescriptor.kind != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
return
}
}
if (intersectionFakeOverrideDescriptor.overriddenDescriptors.size > 1) {
if (intersectionFakeOverrideDescriptor.overriddenDescriptors.firstOrNull {
!it.isInsideInterface
}?.modality == Modality.ABSTRACT
) {
addDiagnostic(AbstractFakeOverrideSuperCall)
}
}
}
}
}
internal object ErrorDescriptorResolutionPart : ResolutionPart() {
@@ -1,16 +0,0 @@
// !LANGUAGE: -ForbidSuperDelegationToAbstractFakeOverride
interface Foo {
fun check(): String = "OK"
}
abstract class Base {
abstract fun check(): String
}
abstract class Derived : Base(), Foo
abstract class Derived2 : Derived() // ONE MORE LEVEL
class Problem : Derived2() {
override fun check(): String {
return super.<!ABSTRACT_SUPER_CALL_WARNING!>check<!>() // NO COMPILER ERROR, BUT FAILURE IN RUNTIME
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: -ForbidSuperDelegationToAbstractFakeOverride
interface Foo {
fun check(): String = "OK"
@@ -9,8 +10,16 @@ abstract class Base {
abstract class Derived : Base(), Foo
abstract class Derived2 : Derived() // ONE MORE LEVEL
abstract class Derived3 : Derived2()
class Problem : Derived2() {
override fun check(): String {
return super.check() // NO COMPILER ERROR, BUT FAILURE IN RUNTIME
return super.<!ABSTRACT_SUPER_CALL_WARNING!>check<!>()
}
}
class Problem2 : Derived3() {
override fun check(): String {
return super.<!ABSTRACT_SUPER_CALL_WARNING!>check<!>()
}
}
@@ -24,6 +24,14 @@ public abstract class Derived2 : Derived {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public abstract class Derived3 : Derived2 {
public constructor Derived3()
public open override /*1*/ /*fake_override*/ fun check(): kotlin.String
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Foo {
public open fun check(): kotlin.String
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@@ -38,3 +46,12 @@ public final class Problem : Derived2 {
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class Problem2 : Derived3 {
public constructor Problem2()
public open override /*1*/ fun check(): kotlin.String
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}