K1: unify code around resolveCallWithGivenDescriptors

This commit is contained in:
Mikhail Glukhikh
2022-07-22 15:32:58 +02:00
committed by teamcity
parent ec055eb418
commit 0bd06b4095
3 changed files with 36 additions and 63 deletions
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.resolve.calls;
import com.intellij.psi.PsiElement;
import kotlin.collections.CollectionsKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
@@ -48,6 +47,7 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.KotlinTypeKt;
import org.jetbrains.kotlin.types.TypeSubstitutor;
@@ -266,23 +266,10 @@ public class CallResolver {
@NotNull Call call,
@NotNull Collection<FunctionDescriptor> functionDescriptors
) {
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS);
OverloadResolutionResults<FunctionDescriptor> resolutionResults = PSICallResolver.runResolutionAndInferenceForGivenDescriptors(
callResolutionContext,
functionDescriptors,
TracingStrategyImpl.create(expression, call),
KotlinCallKind.FUNCTION,
null,
null
TracingStrategy tracingStrategy = TracingStrategyImpl.create(expression, call);
return resolveCallWithGivenDescriptors(
context, call, functionDescriptors, tracingStrategy, null, null, null
);
if (resolutionResults.isSingleResult()) {
context.trace.record(BindingContext.RESOLVED_CALL, call, resolutionResults.getResultingCall());
context.trace.record(BindingContext.CALL, call.getCallElement(), call);
}
return resolutionResults;
}
public OverloadResolutionResults<FunctionDescriptor> resolveSetterCall(
@@ -322,15 +309,35 @@ public class CallResolver {
@NotNull Call call,
@NotNull Collection<FunctionDescriptor> functionDescriptors
) {
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS);
TracingStrategy tracingStrategy = TracingStrategyImpl.create(expression, call);
ReceiverValueWithSmartCastInfo dispatchReceiverValue =
NewResolutionOldInferenceKt.transformToReceiverWithSmartCastInfo(context, receiver);
return resolveCallWithGivenDescriptors(
context, call, functionDescriptors, tracingStrategy, null, null, dispatchReceiverValue
);
}
OverloadResolutionResults<FunctionDescriptor> resolutionResults = PSICallResolver.runResolutionAndInferenceForGivenDescriptors(
@NotNull
public <D extends CallableDescriptor> OverloadResolutionResults<D> resolveCallWithGivenDescriptors(
@NotNull ExpressionTypingContext context,
@NotNull Call call,
@NotNull Collection<D> descriptors,
@NotNull TracingStrategy tracingStrategy,
@Nullable TypeSubstitutor substitutor,
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
@Nullable ReceiverValueWithSmartCastInfo dispatchReceiverValue
) {
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(
context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments
);
OverloadResolutionResults<D> resolutionResults = PSICallResolver.runResolutionAndInferenceForGivenDescriptors(
callResolutionContext,
functionDescriptors,
TracingStrategyImpl.create(expression, call),
descriptors,
tracingStrategy,
KotlinCallKind.FUNCTION,
null,
NewResolutionOldInferenceKt.transformToReceiverWithSmartCastInfo(context, receiver)
substitutor,
dispatchReceiverValue
);
if (resolutionResults.isSingleResult()) {
@@ -341,29 +348,6 @@ public class CallResolver {
return resolutionResults;
}
@NotNull
public <D extends CallableDescriptor> OverloadResolutionResults<D> resolveCallWithGivenDescriptor(
@NotNull ExpressionTypingContext context,
@NotNull Call call,
@NotNull D descriptor,
@NotNull TracingStrategy tracingStrategy,
@Nullable TypeSubstitutor substitutor,
@Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments
) {
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(
context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, dataFlowInfoForArguments
);
return PSICallResolver.runResolutionAndInferenceForGivenDescriptors(
callResolutionContext,
Collections.singletonList(descriptor),
tracingStrategy,
KotlinCallKind.FUNCTION,
substitutor,
null
);
}
@NotNull
public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(
@NotNull BindingTrace trace,
@@ -630,15 +630,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
ReceiverParameterDescriptor descriptor,
KtExpression expression
) {
BindingTrace trace = context.trace;
Call call = CallMaker.makeCall(expression, null, null, expression, Collections.emptyList());
OverloadResolutionResults<ReceiverParameterDescriptor> results =
components.callResolver.resolveCallWithGivenDescriptor(context, call, descriptor, TracingStrategy.EMPTY, null, null);
ResolvedCall<?> resolvedCall = results.getResultingCall();
trace.record(RESOLVED_CALL, call, resolvedCall);
trace.record(CALL, expression, call);
components.callResolver.resolveCallWithGivenDescriptors(
context, call, Collections.singletonList(descriptor), TracingStrategy.EMPTY, null, null, null
);
}
private static boolean isDeclaredInClass(ReceiverParameterDescriptor receiver) {
@@ -161,17 +161,11 @@ public class ControlStructureTypingUtils {
) {
TracingStrategy tracing = createTracingForSpecialConstruction(call, construct.getName(), context);
TypeSubstitutor knownTypeParameterSubstitutor = createKnownTypeParameterSubstitutorForSpecialCall(construct, function, context.expectedType, context.languageVersionSettings);
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithGivenDescriptor(
context, call, function, tracing, knownTypeParameterSubstitutor, dataFlowInfoForArguments
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithGivenDescriptors(
context, call, Collections.singletonList(function), tracing, knownTypeParameterSubstitutor, dataFlowInfoForArguments, null
);
assert results.isSingleResult() : "Not single result after resolving one known candidate";
ResolvedCall<FunctionDescriptor> resolvedCall = results.getResultingCall();
context.trace.record(RESOLVED_CALL, call, resolvedCall);
context.trace.record(CALL, call.getCallElement(), call);
return resolvedCall;
return results.getResultingCall();
}
private static @Nullable TypeSubstitutor createKnownTypeParameterSubstitutorForSpecialCall(