From 48246e5f34a5d0c50b91901fa0fe4404cfc9c875 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Tue, 18 Jul 2017 16:17:38 +0300 Subject: [PATCH] [NI] Add resolution part to check for abstract super call --- .../calls/DiagnosticReporterByTrackingStrategy.kt | 1 + .../tower/KotlinResolutionExternalPredicatesImpl.kt | 7 ++++++- .../resolve/calls/components/ExternalComponents.kt | 1 + .../resolve/calls/components/ResolutionParts.kt | 13 +++++++++++++ .../resolve/calls/model/KotlinCallDiagnistics.kt | 6 ++++++ .../resolve/calls/model/KotlinResolverContext.kt | 2 ++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index b271ff7b015..529fb502708 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -53,6 +53,7 @@ class DiagnosticReporterByTrackingStrategy( VisibilityError::class.java -> tracingStrategy.invisibleMember(trace, (diagnostic as VisibilityError).invisibleMember) NoValueForParameter::class.java -> tracingStrategy.noValueForParameter(trace, (diagnostic as NoValueForParameter).parameterDescriptor) InstantiationOfAbstractClass::class.java -> tracingStrategy.instantiationOfAbstractClass(trace) + AbstractSuperCall::class.java -> tracingStrategy.abstractSuperCall(trace) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionExternalPredicatesImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionExternalPredicatesImpl.kt index 666d5b6d616..9a14dff8201 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionExternalPredicatesImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionExternalPredicatesImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,12 +19,14 @@ package org.jetbrains.kotlin.resolve.calls.tower import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.psi.KtSuperExpression import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isConventionCall import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInfixCall import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isSuperOrDelegatingConstructorCall import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionExternalPredicates import org.jetbrains.kotlin.resolve.calls.model.KotlinCall +import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument import org.jetbrains.kotlin.resolve.isHiddenInResolution class KotlinResolutionExternalPredicatesImpl( @@ -45,4 +47,7 @@ class KotlinResolutionExternalPredicatesImpl( override fun isHiddenInResolution(descriptor: DeclarationDescriptor, kotlinCall: KotlinCall) = descriptor.isHiddenInResolution(languageVersionSettings, isSuperOrDelegatingConstructorCall(kotlinCall)) + + override fun isSuperExpression(receiver: SimpleKotlinCallArgument?): Boolean = + receiver?.psiExpression is KtSuperExpression } \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt index b9fad7bfc54..73ef2b334ff 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt @@ -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. diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 3d1f957e0e5..a70be25d18e 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -270,4 +270,17 @@ internal object CheckOperatorResolutionPart : ResolutionPart { return emptyList() } +} + +internal object CheckAbstractSuperCallPart : ResolutionPart { + override fun SimpleKotlinResolutionCandidate.process(): List { + if (callContext.externalPredicates.isSuperExpression(dispatchReceiverArgument)) { + if (candidateDescriptor is MemberDescriptor && candidateDescriptor.modality == Modality.ABSTRACT) { + return listOf(AbstractSuperCall) + } + } + + return emptyList() + } + } \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnistics.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnistics.kt index 916c32d9f2d..17ead7fdc52 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnistics.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnistics.kt @@ -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) + } +} diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt index 52e7cf192b0..785b7664a87 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinResolverContext.kt @@ -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,