[NI] Report diagnostic on abstract class instantiation.

This commit is contained in:
Dmitry Petrov
2016-10-20 17:44:12 +03:00
committed by Stanislav Erokhin
parent b012681a53
commit 5afd3e72d6
7 changed files with 28 additions and 4 deletions
@@ -16,10 +16,7 @@
package org.jetbrains.kotlin.resolve.calls.components
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.resolve.calls.components.TypeArgumentsToParametersMapper.TypeArgumentsMapping.NoExplicitArguments
import org.jetbrains.kotlin.resolve.calls.inference.model.DeclaredUpperBoundConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.model.ExplicitTypeParameterConstraintPosition
@@ -29,6 +26,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCa
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.*
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.IMPOSSIBLE_TO_GENERATE
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.RUNTIME_ERROR
import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError
import org.jetbrains.kotlin.types.IndexedParametersSubstitution
import org.jetbrains.kotlin.types.TypeSubstitutor
@@ -36,6 +34,17 @@ import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
internal object CheckInstantiationOfAbstractClass : ResolutionPart {
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
if (candidateDescriptor is ConstructorDescriptor && !kotlinCall.isSupertypeConstructorCall) {
if (candidateDescriptor.constructedClass.modality == Modality.ABSTRACT) {
return listOf(InstantiationOfAbstractClass)
}
}
return emptyList()
}
}
internal object CheckVisibility : ResolutionPart {
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
@@ -213,6 +222,10 @@ fun <D : CallableDescriptor> D.safeSubstitute(substitutor: TypeSubstitutor): D =
fun UnwrappedType.substitute(substitutor: TypeSubstitutor): UnwrappedType = substitutor.substitute(this, Variance.INVARIANT)!!.unwrap()
object InstantiationOfAbstractClass : KotlinCallDiagnostic(RUNTIME_ERROR) {
override fun report(reporter: DiagnosticReporter) = reporter.onCall(this)
}
class UnstableSmartCast(val expressionArgument: ExpressionKotlinCallArgument, val targetType: UnwrappedType) :
KotlinCallDiagnostic(ResolutionCandidateApplicability.MAY_THROW_RUNTIME_ERROR) {
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(expressionArgument, this)
@@ -63,5 +63,6 @@ class SimpleConstraintSystemImpl(constraintInjector: ConstraintInjector, resultT
override val externalArgument: KotlinCallArgument? get() = throw UnsupportedOperationException()
override val isInfixCall: Boolean get() = throw UnsupportedOperationException()
override val isOperatorCall: Boolean get() = throw UnsupportedOperationException()
override val isSupertypeConstructorCall: Boolean get() = throw UnsupportedOperationException()
}
}
@@ -37,6 +37,7 @@ interface KotlinCall {
val isInfixCall: Boolean
val isOperatorCall: Boolean
val isSupertypeConstructorCall: Boolean
}
private fun SimpleKotlinCallArgument.checkReceiverInvariants() {
@@ -81,6 +81,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
CheckReceivers
),
FUNCTION(
CheckInstantiationOfAbstractClass,
CheckVisibility,
MapTypeArguments,
MapArguments,