[NI] Add resolution part to check for abstract super call

This commit is contained in:
Mikhail Zarechenskiy
2017-07-18 16:17:38 +03:00
parent b6e195128c
commit 48246e5f34
6 changed files with 29 additions and 1 deletions
@@ -28,6 +28,7 @@ interface KotlinResolutionExternalPredicates {
fun isOperatorCall(kotlinCall: KotlinCall): Boolean
fun isSuperOrDelegatingConstructorCall(kotlinCall: KotlinCall): Boolean
fun isHiddenInResolution(descriptor: DeclarationDescriptor, kotlinCall: KotlinCall): Boolean
fun isSuperExpression(receiver: SimpleKotlinCallArgument?): Boolean
}
// This components hold state (trace). Work with this carefully.
@@ -270,4 +270,17 @@ internal object CheckOperatorResolutionPart : ResolutionPart {
return emptyList()
}
}
internal object CheckAbstractSuperCallPart : ResolutionPart {
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
if (callContext.externalPredicates.isSuperExpression(dispatchReceiverArgument)) {
if (candidateDescriptor is MemberDescriptor && candidateDescriptor.modality == Modality.ABSTRACT) {
return listOf(AbstractSuperCall)
}
}
return emptyList()
}
}
@@ -139,3 +139,9 @@ class UnsafeCallError(val receiver: SimpleKotlinCallArgument) : KotlinCallDiagno
object InstantiationOfAbstractClass : KotlinCallDiagnostic(RUNTIME_ERROR) {
override fun report(reporter: DiagnosticReporter) = reporter.onCall(this)
}
object AbstractSuperCall : KotlinCallDiagnostic(RUNTIME_ERROR) {
override fun report(reporter: DiagnosticReporter) {
reporter.onCall(this)
}
}
@@ -101,6 +101,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
CheckVisibility,
CheckInfixResolutionPart,
CheckOperatorResolutionPart,
CheckAbstractSuperCallPart,
NoTypeArguments,
NoArguments,
CreateDescriptorWithFreshTypeVariables,
@@ -111,6 +112,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
CheckInstantiationOfAbstractClass,
CheckVisibility,
CheckInfixResolutionPart,
CheckAbstractSuperCallPart,
MapTypeArguments,
MapArguments,
CreateDescriptorWithFreshTypeVariables,