[NI] Report diagnostic about receiver as super expression

This commit is contained in:
Mikhail Zarechenskiy
2017-10-27 13:15:08 +03:00
parent 1d6e9c244b
commit f51f7a0fe4
4 changed files with 21 additions and 3 deletions
@@ -89,6 +89,13 @@ class DiagnosticReporterByTrackingStrategy(
val implicitInvokeCheck = (callReceiver as? ReceiverExpressionKotlinCallArgument)?.isVariableReceiverForInvoke ?: false
tracingStrategy.unsafeCall(trace, callReceiver.receiver.receiverValue.type, implicitInvokeCheck)
}
SuperAsExtensionReceiver::class.java -> {
val psiExpression = callReceiver.psiExpression
if (psiExpression is KtSuperExpression) {
trace.report(SUPER_CANT_BE_EXTENSION_RECEIVER.on(psiExpression, psiExpression.text))
}
}
}
}
@@ -291,7 +291,7 @@ internal object CheckOperatorResolutionPart : ResolutionPart() {
}
}
internal object CheckAbstractSuperCallPart : ResolutionPart() {
internal object CheckSuperExpressionCallPart : ResolutionPart() {
override fun KotlinResolutionCandidate.process(workIndex: Int) {
val candidateDescriptor = resolvedCall.candidateDescriptor
@@ -300,6 +300,11 @@ internal object CheckAbstractSuperCallPart : ResolutionPart() {
addDiagnostic(AbstractSuperCall)
}
}
val extensionReceiver = resolvedCall.extensionReceiverArgument
if (extensionReceiver != null && callComponents.statelessCallbacks.isSuperExpression(extensionReceiver)) {
addDiagnostic(SuperAsExtensionReceiver(extensionReceiver))
}
}
}
@@ -156,6 +156,12 @@ object AbstractSuperCall : KotlinCallDiagnostic(RUNTIME_ERROR) {
}
}
class SuperAsExtensionReceiver(val receiver: SimpleKotlinCallArgument) : KotlinCallDiagnostic(RUNTIME_ERROR) {
override fun report(reporter: DiagnosticReporter) {
reporter.onCallReceiver(receiver, this)
}
}
class SpreadArgumentToNonVarargParameter(val argument: KotlinCallArgument) : KotlinCallDiagnostic(RUNTIME_ERROR) {
override fun report(reporter: DiagnosticReporter) {
reporter.onCallArgument(argument, this)
@@ -162,7 +162,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
CheckVisibility,
CheckInfixResolutionPart,
CheckOperatorResolutionPart,
CheckAbstractSuperCallPart,
CheckSuperExpressionCallPart,
NoTypeArguments,
NoArguments,
CreateFreshVariablesSubstitutor,
@@ -173,7 +173,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
CheckInstantiationOfAbstractClass,
CheckVisibility,
CheckInfixResolutionPart,
CheckAbstractSuperCallPart,
CheckSuperExpressionCallPart,
MapTypeArguments,
MapArguments,
ArgumentsToCandidateParameterDescriptor,