diff --git a/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt b/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt index 97b3c80befb..fb7700e4ca2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/frontend/di/injection.kt @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.* -import org.jetbrains.kotlin.resolve.calls.tower.KotlinResolutionExternalPredicatesImpl +import org.jetbrains.kotlin.resolve.calls.tower.KotlinResolutionStatelessCallbacksImpl import org.jetbrains.kotlin.resolve.lazy.* import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory @@ -61,7 +61,7 @@ fun StorageComponentContainer.configureModule( private fun StorageComponentContainer.configurePlatformIndependentComponents() { useImpl() - useImpl() + useImpl() } fun StorageComponentContainer.configureModule( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionExternalPredicatesImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt similarity index 95% rename from compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionExternalPredicatesImpl.kt rename to compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt index 9a14dff8201..b381bee3749 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionExternalPredicatesImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt @@ -24,14 +24,14 @@ 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.components.KotlinResolutionStatelessCallbacks import org.jetbrains.kotlin.resolve.calls.model.KotlinCall import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument import org.jetbrains.kotlin.resolve.isHiddenInResolution -class KotlinResolutionExternalPredicatesImpl( +class KotlinResolutionStatelessCallbacksImpl( private val languageVersionSettings: LanguageVersionSettings -) : KotlinResolutionExternalPredicates { +) : KotlinResolutionStatelessCallbacks { override fun isDescriptorFromSource(descriptor: CallableDescriptor) = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) != null diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index a1c6c969130..2bcc069c009 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -71,7 +71,7 @@ class PSICallResolver( private val dynamicCallableDescriptors: DynamicCallableDescriptors, private val syntheticScopes: SyntheticScopes, private val argumentsToParametersMapper: ArgumentsToParametersMapper, - private val externalPredicates: KotlinResolutionExternalPredicates, + private val statelessCallbacks: KotlinResolutionStatelessCallbacks, private val typeArgumentsToParametersMapper: TypeArgumentsToParametersMapper, private val resultTypeResolver: ResultTypeResolver, private val callableReferenceResolver: CallableReferenceResolver, @@ -98,14 +98,14 @@ class PSICallResolver( val lambdaAnalyzer = createLambdaAnalyzer(context) val callContext = createCallContext(scopeTower, lambdaAnalyzer) - val factoryProviderForInvoke = FactoryProviderForInvoke(context, callContext, kotlinCall) + val factoryProviderForInvoke = FactoryProviderForInvoke(context, callContext, scopeTower, kotlinCall) val expectedType = calculateExpectedType(context) var result = kotlinCallResolver.resolveCall(callContext, kotlinCall, expectedType, factoryProviderForInvoke) val shouldUseOperatorRem = languageVersionSettings.supportsFeature(LanguageFeature.OperatorRem) if (isBinaryRemOperator && shouldUseOperatorRem && (result.isEmpty() || result.areAllCompletedAndInapplicable())) { - result = resolveToDeprecatedMod(name, context, resolutionKind, tracingStrategy, callContext, expectedType) + result = resolveToDeprecatedMod(name, context, resolutionKind, tracingStrategy, callContext, scopeTower, expectedType) } if (result.isEmpty() && reportAdditionalDiagnosticIfNoCandidates(context, scopeTower, resolutionKind.kotlinCallKind, kotlinCall)) { @@ -129,7 +129,7 @@ class PSICallResolver( val callContext = createCallContext(scopeTower, lambdaAnalyzer) val givenCandidates = resolutionCandidates.map { - GivenCandidate(it.descriptor as FunctionDescriptor, + GivenCandidate(scopeTower, it.descriptor as FunctionDescriptor, it.dispatchReceiver?.let { context.transformToReceiverWithSmartCastInfo(it) }, it.knownTypeParametersResultingSubstitutor) } @@ -143,12 +143,14 @@ class PSICallResolver( remOperatorName: Name, context: BasicCallResolutionContext, resolutionKind: NewResolutionOldInference.ResolutionKind, - tracingStrategy: TracingStrategy, callContext: KotlinCallContext, + tracingStrategy: TracingStrategy, + callContext: KotlinCallContext, + scopeTower: ImplicitScopeTower, expectedType: UnwrappedType? ): Collection { val deprecatedName = OperatorConventions.REM_TO_MOD_OPERATION_NAMES[remOperatorName]!! val callWithDeprecatedName = toKotlinCall(context, resolutionKind.kotlinCallKind, context.call, deprecatedName, tracingStrategy) - val refinedProviderForInvokeFactory = FactoryProviderForInvoke(context, callContext, callWithDeprecatedName) + val refinedProviderForInvokeFactory = FactoryProviderForInvoke(context, callContext, scopeTower, callWithDeprecatedName) return kotlinCallResolver.resolveCall(callContext, callWithDeprecatedName, expectedType, refinedProviderForInvokeFactory) } @@ -176,7 +178,7 @@ class PSICallResolver( } private fun createCallContext(scopeTower: ASTScopeTower, resolutionCallbacks: KotlinResolutionCallbacks) = - KotlinCallContext(scopeTower, resolutionCallbacks, externalPredicates, argumentsToParametersMapper, + KotlinCallContext(scopeTower, resolutionCallbacks, statelessCallbacks, argumentsToParametersMapper, typeArgumentsToParametersMapper, resultTypeResolver, callableReferenceResolver, constraintInjector, reflectionTypes) @@ -290,6 +292,7 @@ class PSICallResolver( private inner class FactoryProviderForInvoke( val context: BasicCallResolutionContext, val callContext: KotlinCallContext, + val scopeTower: ImplicitScopeTower, val kotlinCall: PSIKotlinCallImpl ) : CandidateFactoryProviderForInvoke { @@ -314,7 +317,7 @@ class PSICallResolver( override fun factoryForVariable(stripExplicitReceiver: Boolean): CandidateFactory { val explicitReceiver = if (stripExplicitReceiver) null else kotlinCall.explicitReceiver val variableCall = PSIKotlinCallForVariable(kotlinCall, explicitReceiver, kotlinCall.name) - return SimpleCandidateFactory(callContext, variableCall) + return SimpleCandidateFactory(callContext, scopeTower, variableCall) } override fun factoryForInvoke(variable: KotlinResolutionCandidate, useExplicitReceiver: Boolean): @@ -338,7 +341,7 @@ class PSICallResolver( PSIKotlinCallForInvoke(kotlinCall, variableCallArgument, null) } - return variableCallArgument.receiver to SimpleCandidateFactory(callContext, callForInvoke) + return variableCallArgument.receiver to SimpleCandidateFactory(callContext, scopeTower, callForInvoke) } // todo: create special check that there is no invoke on variable diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt index 4b898f6aae3..e9ec44b99c1 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/KotlinCallResolver.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.resolve.calls import org.jetbrains.kotlin.resolve.calls.components.KotlinCallCompleter +import org.jetbrains.kotlin.resolve.calls.components.KotlinResolutionCallbacks import org.jetbrains.kotlin.resolve.calls.components.NewOverloadingConflictResolver import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode import org.jetbrains.kotlin.resolve.calls.model.* @@ -42,7 +43,7 @@ class KotlinCallResolver( kotlinCall.checkCallInvariants() - val candidateFactory = SimpleCandidateFactory(callContext, kotlinCall) + val candidateFactory = SimpleCandidateFactory(callContext, scopeTower, kotlinCall) val processor = when(kotlinCall.callKind) { KotlinCallKind.VARIABLE -> { createVariableAndObjectProcessor(scopeTower, kotlinCall.name, candidateFactory, kotlinCall.explicitReceiver?.receiver) @@ -55,7 +56,7 @@ class KotlinCallResolver( val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = kotlinCall.callKind != KotlinCallKind.UNSUPPORTED) - return choseMostSpecific(callContext, expectedType, candidates) + return choseMostSpecific(callContext.resolutionCallbacks, expectedType, candidates) } fun resolveGivenCandidates( @@ -70,6 +71,7 @@ class KotlinCallResolver( val resolutionCandidates = givenCandidates.map { SimpleKotlinResolutionCandidate(callContext, + it.scopeTower, kotlinCall, if (it.dispatchReceiver == null) ExplicitReceiverKind.NO_EXPLICIT_RECEIVER else ExplicitReceiverKind.DISPATCH_RECEIVER, it.dispatchReceiver?.let { ReceiverExpressionKotlinCallArgument(it, isSafeCall) }, @@ -82,30 +84,31 @@ class KotlinCallResolver( val candidates = towerResolver.runWithEmptyTowerData(KnownResultProcessor(resolutionCandidates), TowerResolver.SuccessfulResultCollector { it.status }, useOrder = true) - return choseMostSpecific(callContext, expectedType, candidates) + return choseMostSpecific(callContext.resolutionCallbacks, expectedType, candidates) } private fun choseMostSpecific( - callContext: KotlinCallContext, + resolutionCallbacks: KotlinResolutionCallbacks, expectedType: UnwrappedType?, candidates: Collection ): Collection { + val isDebuggerContext = (candidates.firstOrNull() ?: return emptyList()).lastCall.scopeTower.isDebuggerContext val maximallySpecificCandidates = overloadingConflictResolver.chooseMaximallySpecificCandidates( candidates, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, discriminateGenerics = true, // todo - isDebuggerContext = callContext.scopeTower.isDebuggerContext) + isDebuggerContext = isDebuggerContext) val singleResult = maximallySpecificCandidates.singleOrNull()?.let { - kotlinCallCompleter.completeCallIfNecessary(it, expectedType, callContext.resolutionCallbacks) + kotlinCallCompleter.completeCallIfNecessary(it, expectedType, resolutionCallbacks) } if (singleResult != null) { return listOf(singleResult) } return maximallySpecificCandidates.map { - kotlinCallCompleter.transformWhenAmbiguity(it, callContext.resolutionCallbacks) + kotlinCallCompleter.transformWhenAmbiguity(it, resolutionCallbacks) } } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt index 4611e9769d0..7549b5cca26 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt @@ -153,12 +153,13 @@ private fun ConstraintSystemOperation.addReceiverConstraint( class CallableReferencesCandidateFactory( val argument: CallableReferenceKotlinCallArgument, val outerCallContext: KotlinCallContext, + val scopeTower: ImplicitScopeTower, val compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit, val expectedType: UnwrappedType? ) : CandidateFactory { fun createCallableProcessor(explicitReceiver: DetailedReceiver?) = - createCallableReferenceProcessor(outerCallContext.scopeTower, argument.rhsName, this, explicitReceiver) + createCallableReferenceProcessor(scopeTower, argument.rhsName, this, explicitReceiver) override fun createCandidate( towerCandidate: CandidateWithBoundDispatchReceiver, @@ -189,7 +190,7 @@ class CallableReferencesCandidateFactory( if (it.hasContradiction) return@compatibilityChecker val (_, visibilityError) = it.checkCallableReference(argument, dispatchCallableReceiver, extensionCallableReceiver, candidateDescriptor, - reflectionCandidateType, expectedType, outerCallContext.scopeTower.lexicalScope.ownerDescriptor) + reflectionCandidateType, expectedType, scopeTower.lexicalScope.ownerDescriptor) diagnostics.addIfNotNull(visibilityError) @@ -273,7 +274,7 @@ class CallableReferencesCandidateFactory( val mutable = descriptor.isVar && run { val setter = descriptor.setter setter == null || Visibilities.isVisible(dispatchReceiver?.asReceiverValueForVisibilityChecks, setter, - outerCallContext.scopeTower.lexicalScope.ownerDescriptor) + scopeTower.lexicalScope.ownerDescriptor) } return outerCallContext.reflectionTypes.getKPropertyType(Annotations.EMPTY, argumentsAndReceivers, descriptorReturnType, mutable) to 0 diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt index 1a492cb2aee..70fb2bdfa0d 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.resolve.calls.results.FlatSignature import org.jetbrains.kotlin.resolve.calls.results.OverloadingConflictResolver import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator +import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower import org.jetbrains.kotlin.resolve.calls.tower.TowerResolver import org.jetbrains.kotlin.types.UnwrappedType @@ -34,7 +35,7 @@ import org.jetbrains.kotlin.types.UnwrappedType class CallableReferenceOverloadConflictResolver( builtIns: KotlinBuiltIns, specificityComparator: TypeSpecificityComparator, - externalPredicates: KotlinResolutionExternalPredicates, + statelessCallbacks: KotlinResolutionStatelessCallbacks, constraintInjector: ConstraintInjector, typeResolver: ResultTypeResolver ) : OverloadingConflictResolver( @@ -44,7 +45,7 @@ class CallableReferenceOverloadConflictResolver( { SimpleConstraintSystemImpl(constraintInjector, typeResolver) }, Companion::createFlatSignature, { null }, - { externalPredicates.isDescriptorFromSource(it) } + { statelessCallbacks.isDescriptorFromSource(it) } ) { companion object { private fun createFlatSignature(candidate: CallableReferenceCandidate) = @@ -54,6 +55,7 @@ class CallableReferenceOverloadConflictResolver( fun processCallableReferenceArgument( callContext: KotlinCallContext, + scopeTower: ImplicitScopeTower, csBuilder: ConstraintSystemBuilder, postponedArgument: PostponedCallableReferenceArgument ): KotlinCallDiagnostic? { @@ -64,7 +66,7 @@ fun processCallableReferenceArgument( if (subLHSCall != null) { csBuilder.addInnerCall(subLHSCall.resolvedCall) } - val candidates = callContext.callableReferenceResolver.runRLSResolution(callContext, argument, expectedType) { checkCallableReference -> + val candidates = callContext.callableReferenceResolver.runRLSResolution(callContext, scopeTower, argument, expectedType) { checkCallableReference -> csBuilder.runTransaction { checkCallableReference(this); false } } val chosenCandidate = when (candidates.size) { @@ -74,7 +76,7 @@ fun processCallableReferenceArgument( } val (toFreshSubstitutor, diagnostic) = with(chosenCandidate) { csBuilder.checkCallableReference(argument, dispatchReceiver, extensionReceiver, candidate, - reflectionCandidateType, expectedType, callContext.scopeTower.lexicalScope.ownerDescriptor) + reflectionCandidateType, expectedType, scopeTower.lexicalScope.ownerDescriptor) } postponedArgument.analyzedAndThereIsResult = true @@ -92,16 +94,17 @@ class CallableReferenceResolver( fun runRLSResolution( outerCallContext: KotlinCallContext, + scopeTower: ImplicitScopeTower, callableReference: CallableReferenceKotlinCallArgument, expectedType: UnwrappedType?, // this type can have not fixed type variable inside compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit // you can run anything throw this operation and all this operation will be roll backed ): Set { - val factory = CallableReferencesCandidateFactory(callableReference, outerCallContext, compatibilityChecker, expectedType) + val factory = CallableReferencesCandidateFactory(callableReference, outerCallContext, scopeTower, compatibilityChecker, expectedType) val processor = createCallableReferenceProcessor(factory) - val candidates = towerResolver.runResolve(outerCallContext.scopeTower, processor, useOrder = true) + val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = true) return callableReferenceOverloadConflictResolver.chooseMaximallySpecificCandidates(candidates, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, discriminateGenerics = false, - isDebuggerContext = outerCallContext.scopeTower.isDebuggerContext) + isDebuggerContext = scopeTower.isDebuggerContext) } } 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 c2cce81a9e6..cc12152efe9 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 @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.types.UnwrappedType // stateless component -interface KotlinResolutionExternalPredicates { +interface KotlinResolutionStatelessCallbacks { fun isDescriptorFromSource(descriptor: CallableDescriptor): Boolean fun isInfixCall(kotlinCall: KotlinCall): Boolean fun isOperatorCall(kotlinCall: KotlinCall): Boolean diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index 10d8f67c5b5..40b9e75e051 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -93,7 +93,7 @@ class KotlinCallCompleter( private fun resolveCallableReferenceArguments(c: Context, topLevelCall: SimpleKotlinResolutionCandidate) { for (callableReferenceArgument in c.postponedArguments) { if (callableReferenceArgument !is PostponedCallableReferenceArgument) continue - processCallableReferenceArgument(topLevelCall.callContext, c.getBuilder(), callableReferenceArgument) + processCallableReferenceArgument(topLevelCall.callContext, topLevelCall.scopeTower, c.getBuilder(), callableReferenceArgument) } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt index a0ff7c63712..f5e80cdd781 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/NewOverloadingConflictResolver.kt @@ -31,7 +31,7 @@ import java.util.* class NewOverloadingConflictResolver( builtIns: KotlinBuiltIns, specificityComparator: TypeSpecificityComparator, - externalPredicates: KotlinResolutionExternalPredicates, + statelessCallbacks: KotlinResolutionStatelessCallbacks, constraintInjector: ConstraintInjector, typeResolver: ResultTypeResolver ) : OverloadingConflictResolver( @@ -45,7 +45,7 @@ class NewOverloadingConflictResolver( { SimpleConstraintSystemImpl(constraintInjector, typeResolver) }, Companion::createFlatSignature, { (it as? VariableAsFunctionKotlinResolutionCandidate)?.resolvedVariable }, - { externalPredicates.isDescriptorFromSource(it) } + { statelessCallbacks.isDescriptorFromSource(it) } ) { companion object { 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 3387cbe94d3..d6d20b4257d 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 @@ -37,7 +37,7 @@ import org.jetbrains.kotlin.utils.addIfNotNull internal object CheckInstantiationOfAbstractClass : ResolutionPart { override fun SimpleKotlinResolutionCandidate.process(): List { - if (candidateDescriptor is ConstructorDescriptor && !callContext.externalPredicates.isSuperOrDelegatingConstructorCall(kotlinCall)) { + if (candidateDescriptor is ConstructorDescriptor && !callContext.statelessCallbacks.isSuperOrDelegatingConstructorCall(kotlinCall)) { if (candidateDescriptor.constructedClass.modality == Modality.ABSTRACT) { return listOf(InstantiationOfAbstractClass) } @@ -62,7 +62,7 @@ internal object CheckVisibility : ResolutionPart { return listOf(VisibilityError(invisibleMember)) } - private val SimpleKotlinResolutionCandidate.containingDescriptor: DeclarationDescriptor get() = callContext.scopeTower.lexicalScope.ownerDescriptor + private val SimpleKotlinResolutionCandidate.containingDescriptor: DeclarationDescriptor get() = scopeTower.lexicalScope.ownerDescriptor } internal object MapTypeArguments : ResolutionPart { @@ -253,7 +253,7 @@ internal object CheckArguments : ResolutionPart { internal object CheckInfixResolutionPart : ResolutionPart { override fun SimpleKotlinResolutionCandidate.process(): List { - if (callContext.externalPredicates.isInfixCall(kotlinCall) && + if (callContext.statelessCallbacks.isInfixCall(kotlinCall) && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix)) { return listOf(InfixCallNoInfixModifier) } @@ -264,7 +264,7 @@ internal object CheckInfixResolutionPart : ResolutionPart { internal object CheckOperatorResolutionPart : ResolutionPart { override fun SimpleKotlinResolutionCandidate.process(): List { - if (callContext.externalPredicates.isOperatorCall(kotlinCall) && + if (callContext.statelessCallbacks.isOperatorCall(kotlinCall) && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) { return listOf(InvokeConventionCallNoOperatorModifier) } 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 785b7664a87..76de15cb860 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 @@ -33,7 +33,7 @@ import org.jetbrains.kotlin.types.isDynamic class KotlinCallContext( val scopeTower: ImplicitScopeTower, val resolutionCallbacks: KotlinResolutionCallbacks, - val externalPredicates: KotlinResolutionExternalPredicates, + val statelessCallbacks: KotlinResolutionStatelessCallbacks, val argumentsToParametersMapper: ArgumentsToParametersMapper, val typeArgumentsToParametersMapper: TypeArgumentsToParametersMapper, val resultTypeResolver: ResultTypeResolver, @@ -42,7 +42,11 @@ class KotlinCallContext( val reflectionTypes: ReflectionTypes ) -class SimpleCandidateFactory(val callContext: KotlinCallContext, val kotlinCall: KotlinCall): CandidateFactory { +class SimpleCandidateFactory( + val callContext: KotlinCallContext, + val scopeTower: ImplicitScopeTower, + val kotlinCall: KotlinCall +): CandidateFactory { // todo: try something else, because current method is ugly and unstable private fun createReceiverArgument( @@ -73,11 +77,11 @@ class SimpleCandidateFactory(val callContext: KotlinCallContext, val kotlinCall: val extensionArgumentReceiver = createReceiverArgument(kotlinCall.getExplicitExtensionReceiver(explicitReceiverKind), extensionReceiver) if (ErrorUtils.isError(towerCandidate.descriptor)) { - return ErrorKotlinResolutionCandidate(callContext, kotlinCall, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver, towerCandidate.descriptor) + return ErrorKotlinResolutionCandidate(callContext, scopeTower, kotlinCall, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver, towerCandidate.descriptor) } val candidateDiagnostics = towerCandidate.diagnostics.toMutableList() - if (callContext.externalPredicates.isHiddenInResolution(towerCandidate.descriptor, kotlinCall)) { + if (callContext.statelessCallbacks.isHiddenInResolution(towerCandidate.descriptor, kotlinCall)) { candidateDiagnostics.add(HiddenDescriptor) } @@ -91,7 +95,7 @@ class SimpleCandidateFactory(val callContext: KotlinCallContext, val kotlinCall: } } - return SimpleKotlinResolutionCandidate(callContext, kotlinCall, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver, + return SimpleKotlinResolutionCandidate(callContext, scopeTower, kotlinCall, explicitReceiverKind, dispatchArgumentReceiver, extensionArgumentReceiver, towerCandidate.descriptor, null, candidateDiagnostics) } } @@ -126,6 +130,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) { } class GivenCandidate( + val scopeTower: ImplicitScopeTower, val descriptor: FunctionDescriptor, val dispatchReceiver: ReceiverValueWithSmartCastInfo?, val knownTypeParametersResultingSubstitutor: TypeSubstitutor? diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionCandidate.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionCandidate.kt index 0e592c9a55f..416007bf49d 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionCandidate.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionCandidate.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImp import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tower.Candidate +import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateStatus import org.jetbrains.kotlin.resolve.calls.tower.isSuccess import org.jetbrains.kotlin.types.TypeSubstitutor @@ -105,6 +106,7 @@ sealed class AbstractSimpleKotlinResolutionCandidate( open class SimpleKotlinResolutionCandidate( val callContext: KotlinCallContext, + val scopeTower: ImplicitScopeTower, override val kotlinCall: KotlinCall, val explicitReceiverKind: ExplicitReceiverKind, val dispatchReceiverArgument: SimpleKotlinCallArgument?, @@ -133,12 +135,14 @@ open class SimpleKotlinResolutionCandidate( class ErrorKotlinResolutionCandidate( callContext: KotlinCallContext, + scopeTower: ImplicitScopeTower, kotlinCall: KotlinCall, explicitReceiverKind: ExplicitReceiverKind, dispatchReceiverArgument: SimpleKotlinCallArgument?, extensionReceiver: SimpleKotlinCallArgument?, candidateDescriptor: CallableDescriptor -) : SimpleKotlinResolutionCandidate(callContext, kotlinCall, explicitReceiverKind, dispatchReceiverArgument, extensionReceiver, candidateDescriptor, null, listOf()) { +) : SimpleKotlinResolutionCandidate(callContext, scopeTower, kotlinCall, explicitReceiverKind, dispatchReceiverArgument, + extensionReceiver, candidateDescriptor, null, listOf()) { override val resolutionSequence: List get() = emptyList() init {