K1: unify code around resolveCallWithGivenDescriptors
This commit is contained in:
committed by
teamcity
parent
ec055eb418
commit
0bd06b4095
@@ -6,7 +6,6 @@
|
|||||||
package org.jetbrains.kotlin.resolve.calls;
|
package org.jetbrains.kotlin.resolve.calls;
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import kotlin.collections.CollectionsKt;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.builtins.FunctionTypesKt;
|
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.SyntheticScopes;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
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.KotlinType;
|
||||||
import org.jetbrains.kotlin.types.KotlinTypeKt;
|
import org.jetbrains.kotlin.types.KotlinTypeKt;
|
||||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||||
@@ -266,23 +266,10 @@ public class CallResolver {
|
|||||||
@NotNull Call call,
|
@NotNull Call call,
|
||||||
@NotNull Collection<FunctionDescriptor> functionDescriptors
|
@NotNull Collection<FunctionDescriptor> functionDescriptors
|
||||||
) {
|
) {
|
||||||
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS);
|
TracingStrategy tracingStrategy = TracingStrategyImpl.create(expression, call);
|
||||||
|
return resolveCallWithGivenDescriptors(
|
||||||
OverloadResolutionResults<FunctionDescriptor> resolutionResults = PSICallResolver.runResolutionAndInferenceForGivenDescriptors(
|
context, call, functionDescriptors, tracingStrategy, null, null, null
|
||||||
callResolutionContext,
|
|
||||||
functionDescriptors,
|
|
||||||
TracingStrategyImpl.create(expression, call),
|
|
||||||
KotlinCallKind.FUNCTION,
|
|
||||||
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(
|
public OverloadResolutionResults<FunctionDescriptor> resolveSetterCall(
|
||||||
@@ -322,15 +309,35 @@ public class CallResolver {
|
|||||||
@NotNull Call call,
|
@NotNull Call call,
|
||||||
@NotNull Collection<FunctionDescriptor> functionDescriptors
|
@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,
|
callResolutionContext,
|
||||||
functionDescriptors,
|
descriptors,
|
||||||
TracingStrategyImpl.create(expression, call),
|
tracingStrategy,
|
||||||
KotlinCallKind.FUNCTION,
|
KotlinCallKind.FUNCTION,
|
||||||
null,
|
substitutor,
|
||||||
NewResolutionOldInferenceKt.transformToReceiverWithSmartCastInfo(context, receiver)
|
dispatchReceiverValue
|
||||||
);
|
);
|
||||||
|
|
||||||
if (resolutionResults.isSingleResult()) {
|
if (resolutionResults.isSingleResult()) {
|
||||||
@@ -341,29 +348,6 @@ public class CallResolver {
|
|||||||
return resolutionResults;
|
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
|
@NotNull
|
||||||
public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(
|
public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
|
|||||||
+3
-8
@@ -630,15 +630,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
ReceiverParameterDescriptor descriptor,
|
ReceiverParameterDescriptor descriptor,
|
||||||
KtExpression expression
|
KtExpression expression
|
||||||
) {
|
) {
|
||||||
BindingTrace trace = context.trace;
|
|
||||||
Call call = CallMaker.makeCall(expression, null, null, expression, Collections.emptyList());
|
Call call = CallMaker.makeCall(expression, null, null, expression, Collections.emptyList());
|
||||||
OverloadResolutionResults<ReceiverParameterDescriptor> results =
|
components.callResolver.resolveCallWithGivenDescriptors(
|
||||||
components.callResolver.resolveCallWithGivenDescriptor(context, call, descriptor, TracingStrategy.EMPTY, null, null);
|
context, call, Collections.singletonList(descriptor), TracingStrategy.EMPTY, null, null, null
|
||||||
|
);
|
||||||
ResolvedCall<?> resolvedCall = results.getResultingCall();
|
|
||||||
|
|
||||||
trace.record(RESOLVED_CALL, call, resolvedCall);
|
|
||||||
trace.record(CALL, expression, call);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isDeclaredInClass(ReceiverParameterDescriptor receiver) {
|
private static boolean isDeclaredInClass(ReceiverParameterDescriptor receiver) {
|
||||||
|
|||||||
+3
-9
@@ -161,17 +161,11 @@ public class ControlStructureTypingUtils {
|
|||||||
) {
|
) {
|
||||||
TracingStrategy tracing = createTracingForSpecialConstruction(call, construct.getName(), context);
|
TracingStrategy tracing = createTracingForSpecialConstruction(call, construct.getName(), context);
|
||||||
TypeSubstitutor knownTypeParameterSubstitutor = createKnownTypeParameterSubstitutorForSpecialCall(construct, function, context.expectedType, context.languageVersionSettings);
|
TypeSubstitutor knownTypeParameterSubstitutor = createKnownTypeParameterSubstitutorForSpecialCall(construct, function, context.expectedType, context.languageVersionSettings);
|
||||||
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithGivenDescriptor(
|
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithGivenDescriptors(
|
||||||
context, call, function, tracing, knownTypeParameterSubstitutor, dataFlowInfoForArguments
|
context, call, Collections.singletonList(function), tracing, knownTypeParameterSubstitutor, dataFlowInfoForArguments, null
|
||||||
);
|
);
|
||||||
assert results.isSingleResult() : "Not single result after resolving one known candidate";
|
assert results.isSingleResult() : "Not single result after resolving one known candidate";
|
||||||
|
return results.getResultingCall();
|
||||||
ResolvedCall<FunctionDescriptor> resolvedCall = results.getResultingCall();
|
|
||||||
|
|
||||||
context.trace.record(RESOLVED_CALL, call, resolvedCall);
|
|
||||||
context.trace.record(CALL, call.getCallElement(), call);
|
|
||||||
|
|
||||||
return resolvedCall;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable TypeSubstitutor createKnownTypeParameterSubstitutorForSpecialCall(
|
private static @Nullable TypeSubstitutor createKnownTypeParameterSubstitutorForSpecialCall(
|
||||||
|
|||||||
Reference in New Issue
Block a user