From 4b8e95c243b37f525cca19f3f22e9978829ae980 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Tue, 1 May 2018 23:03:22 +0300 Subject: [PATCH] Minor. Extract preparation for expected type to separate function --- .../calls/components/ResolutionParts.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) 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 fcf4cbd7f82..1455a6987ef 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 @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.resolve.calls.tower.InvokeConventionCallNoOperatorMo import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.typeUtil.contains +import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.utils.addToStdlib.safeAs internal object CheckInstantiationOfAbstractClass : ResolutionPart() { @@ -235,14 +236,19 @@ private fun KotlinResolutionCandidate.resolveKotlinArgument( candidateParameter: ParameterDescriptor?, isReceiver: Boolean ) { - val expectedType = candidateParameter?.let { - val argumentType = argument.getExpectedType(candidateParameter, callComponents.languageVersionSettings) - val resultType = knownTypeParametersResultingSubstitutor?.substitute(argumentType) ?: argumentType - resolvedCall.substitutor.substituteKeepAnnotations(resultType) - } + val expectedType = candidateParameter?.let { prepareExpectedType(argument, candidateParameter) } addResolvedKtPrimitive(resolveKtPrimitive(csBuilder, argument, expectedType, this, isReceiver)) } +private fun KotlinResolutionCandidate.prepareExpectedType( + argument: KotlinCallArgument, + candidateParameter: ParameterDescriptor +): UnwrappedType { + val argumentType = argument.getExpectedType(candidateParameter, callComponents.languageVersionSettings) + val resultType = knownTypeParametersResultingSubstitutor?.substitute(argumentType) ?: argumentType + return resolvedCall.substitutor.substituteKeepAnnotations(resultType) +} + internal object CheckReceivers : ResolutionPart() { private fun KotlinResolutionCandidate.checkReceiver( receiverArgument: SimpleKotlinCallArgument?, @@ -288,7 +294,8 @@ internal object CheckInfixResolutionPart : ResolutionPart() { override fun KotlinResolutionCandidate.process(workIndex: Int) { val candidateDescriptor = resolvedCall.candidateDescriptor if (callComponents.statelessCallbacks.isInfixCall(kotlinCall) && - (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix)) { + (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix) + ) { addDiagnostic(InfixCallNoInfixModifier) } } @@ -298,7 +305,8 @@ internal object CheckOperatorResolutionPart : ResolutionPart() { override fun KotlinResolutionCandidate.process(workIndex: Int) { val candidateDescriptor = resolvedCall.candidateDescriptor if (callComponents.statelessCallbacks.isOperatorCall(kotlinCall) && - (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) { + (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator) + ) { addDiagnostic(InvokeConventionCallNoOperatorModifier) } }