From 859a8adc3194ee1ac9a913dc27a1042a65fb253d Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Mon, 7 Dec 2015 19:32:09 +0300 Subject: [PATCH] Fix priority for functions without infix or operator modifier --- .../calls/tower/NewResolveOldInference.kt | 18 ++++++++++++++++-- .../kotlin/resolve/calls/tower/ScopeTower.kt | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolveOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolveOldInference.kt index 7008a7ffd65..398dbcebf68 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolveOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolveOldInference.kt @@ -21,10 +21,13 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.psi.Call import org.jetbrains.kotlin.resolve.TemporaryBindingTrace import org.jetbrains.kotlin.resolve.calls.CallResolver import org.jetbrains.kotlin.resolve.calls.CallTransformer import org.jetbrains.kotlin.resolve.calls.CandidateResolver +import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isConventionCall +import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isInfixCall import org.jetbrains.kotlin.resolve.calls.callUtil.createLookupLocation import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.kotlin.resolve.calls.context.CallCandidateResolutionContext @@ -35,13 +38,13 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallImpl import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCallImpl import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsImpl import org.jetbrains.kotlin.resolve.calls.results.ResolutionResultsHandler -import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallableDescriptors import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategyForInvoke import org.jetbrains.kotlin.resolve.isAnnotatedAsHidden import org.jetbrains.kotlin.resolve.scopes.receivers.* +import org.jetbrains.kotlin.types.ErrorUtils import org.jetbrains.kotlin.types.isDynamic import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.utils.addToStdlib.check @@ -207,10 +210,20 @@ class NewResolveOldInference( ) candidateResolver.performResolutionForCandidateCall(callCandidateResolutionContext, basicCallContext.checkArguments) // todo - val diagnostics = (towerCandidate.diagnostics + createPreviousResolveError(candidateCall.status)).filterNotNull() // todo + val diagnostics = (towerCandidate.diagnostics + + checkInfixAndOperator(basicCallContext.call, towerCandidate.descriptor) + + createPreviousResolveError(candidateCall.status)).filterNotNull() // todo return Candidate(ResolutionCandidateStatus(diagnostics), candidateCall) } + private fun checkInfixAndOperator(call: Call, descriptor: CallableDescriptor): List { + if (descriptor !is FunctionDescriptor || ErrorUtils.isError(descriptor)) return emptyList() + + val conventionError = if (isConventionCall(call) && !descriptor.isOperator) InvokeConventionCallNoOperatorModifier else null + val infixError = if (isInfixCall(call) && !descriptor.isInfix) InfixCallNoInfixModifier else null + return listOfNotNull(conventionError, infixError) + } + override fun getStatus(candidate: Candidate): ResolutionCandidateStatus = candidate.candidateStatus override fun transformCandidate(variable: Candidate, invoke: Candidate): Candidate { @@ -251,6 +264,7 @@ class NewResolveOldInference( variableReceiver, basicCallContext.call) val tracingForInvoke = TracingStrategyForInvoke(calleeExpression, functionCall, variableReceiver.type) val basicCallResolutionContext = basicCallContext.replaceBindingTrace(variable.resolvedCall.trace) + .replaceCall(functionCall) .replaceContextDependency(ContextDependency.DEPENDENT) // todo val newContext = Context(scopeTower, OperatorNameConventions.INVOKE, basicCallResolutionContext, tracingForInvoke) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTower.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTower.kt index 4e22c916b3a..834ca890225 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTower.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTower.kt @@ -100,4 +100,5 @@ object UnstableSmartCastDiagnostic: ResolutionDiagnostic(ResolutionCandidateAppl object ExtensionWithStaticTypeWithDynamicReceiver: ResolutionDiagnostic(ResolutionCandidateApplicability.HIDDEN) object HiddenDescriptor: ResolutionDiagnostic(ResolutionCandidateApplicability.HIDDEN) - +object InvokeConventionCallNoOperatorModifier : ResolutionDiagnostic(ResolutionCandidateApplicability.CONVENTION_ERROR) +object InfixCallNoInfixModifier : ResolutionDiagnostic(ResolutionCandidateApplicability.CONVENTION_ERROR) \ No newline at end of file