K1: report ABSTRACT_SUPER_CALL(_WARNING) also for 2+ steps to intersection
#KT-53953 Fixed
This commit is contained in:
+23
-9
@@ -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() {
|
||||
|
||||
Vendored
-16
@@ -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
|
||||
}
|
||||
}
|
||||
Vendored
+10
-1
@@ -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<!>()
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+17
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user