From a5dffafacd0d9fedbcd9c8b1ac06b27a5905badd Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Tue, 13 Jun 2017 11:39:55 +0300 Subject: [PATCH] [NI] Fix provideDelegate resolution. For provideDelegate there is no real psi for resolution, so we write corresponding call via special trace key. --- .../kotlin/resolve/BindingContext.java | 1 + .../resolve/DelegatedPropertyResolver.kt | 4 ++++ .../tower/KotlinToResolvedCallTransformer.kt | 18 ++++++++++-------- .../resolve/calls/tower/PSICallResolver.kt | 8 ++++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java index 6b1a3a4cc97..714ca13f5f1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java @@ -123,6 +123,7 @@ public interface BindingContext { WritableSlice> RESOLVED_CALL = new BasicWritableSlice<>(DO_NOTHING); WritableSlice ONLY_RESOLVED_CALL = new BasicWritableSlice<>(DO_NOTHING); + WritableSlice DELEGATE_EXPRESSION_TO_PROVIDE_DELEGATE_CALL = new BasicWritableSlice<>(DO_NOTHING); WritableSlice TAIL_RECURSION_CALL = Slices.createSimpleSlice(); WritableSlice CONSTRAINT_SYSTEM_COMPLETER = new BasicWritableSlice<>(DO_NOTHING); WritableSlice CALL = new BasicWritableSlice<>(DO_NOTHING); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt index 5905a3151fd..317232ed215 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyResolver.kt @@ -337,6 +337,10 @@ class DelegatedPropertyResolver( val (provideDelegateCall, provideDelegateResults) = fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments, functionName, delegateExpression) + + if (provideDelegateResults.isSingleResult) { + context.trace.record(BindingContext.DELEGATE_EXPRESSION_TO_PROVIDE_DELEGATE_CALL, delegateExpression, provideDelegateCall) + } context.trace.record(BindingContext.PROVIDE_DELEGATE_CALL, propertyDescriptor, provideDelegateCall) return provideDelegateResults diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index ac5824a22fa..46fd83d597c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.resolve.calls.tower -import com.intellij.psi.PsiElement import org.jetbrains.kotlin.builtins.replaceReturnType import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.* @@ -42,7 +41,10 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.ErrorUtils +import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.TypeUtils +import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils import java.util.* @@ -476,12 +478,12 @@ class NewResolvedCallImpl( } override fun getSmartCastDispatchReceiverType(): KotlinType? = null // todo +} - fun ResolutionCandidateApplicability.toResolutionStatus(): ResolutionStatus = when (this) { - ResolutionCandidateApplicability.RESOLVED, ResolutionCandidateApplicability.RESOLVED_LOW_PRIORITY -> ResolutionStatus.SUCCESS - ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER -> ResolutionStatus.RECEIVER_TYPE_ERROR - else -> ResolutionStatus.OTHER_ERROR - } +fun ResolutionCandidateApplicability.toResolutionStatus(): ResolutionStatus = when (this) { + ResolutionCandidateApplicability.RESOLVED, ResolutionCandidateApplicability.RESOLVED_LOW_PRIORITY -> ResolutionStatus.SUCCESS + ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER -> ResolutionStatus.RECEIVER_TYPE_ERROR + else -> ResolutionStatus.OTHER_ERROR } class NewVariableAsFunctionResolvedCallImpl( @@ -491,7 +493,7 @@ class NewVariableAsFunctionResolvedCallImpl( ): VariableAsFunctionResolvedCall, ResolvedCall by functionCall class StubOnlyResolvedCall(val candidate: SimpleKotlinResolutionCandidate): NewAbstractResolvedCall() { - override fun getStatus() = ResolutionStatus.UNKNOWN_STATUS + override fun getStatus() = candidate.status.resultingApplicability.toResolutionStatus() override fun getCandidateDescriptor(): D = candidate.candidateDescriptor as D override fun getResultingDescriptor(): D = candidate.descriptorWithFreshTypes as D 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 5723262ebbd..1d4b2c7dbb0 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 @@ -433,8 +433,12 @@ class PSICallResolver( if (oldReceiver is ExpressionReceiver) { val ktExpression = KtPsiUtil.getLastElementDeparenthesized(oldReceiver.expression, context.statementFilter) - val onlyResolvedCall = ktExpression?.getCall(context.trace.bindingContext)?.let { - context.trace.get(BindingContext.ONLY_RESOLVED_CALL, it) + val bindingContext = context.trace.bindingContext + val call = bindingContext[BindingContext.DELEGATE_EXPRESSION_TO_PROVIDE_DELEGATE_CALL, ktExpression] + ?: ktExpression?.getCall(bindingContext) + + val onlyResolvedCall = call?.let { + bindingContext.get(BindingContext.ONLY_RESOLVED_CALL, it) } if (onlyResolvedCall != null) { subCallArgument = SubKotlinCallArgumentImpl(CallMaker.makeExternalValueArgument(oldReceiver.expression),