Revert "[FE 1.0] Resolve setters through the new type inference infra"

This reverts commit 6e191147b9.
This commit is contained in:
Mikhail Glukhikh
2022-09-12 11:28:30 +02:00
committed by Space
parent 8be08d903b
commit a9b8f6715b
12 changed files with 58 additions and 70 deletions
@@ -20,12 +20,8 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticFactory0;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
import org.jetbrains.kotlin.resolve.*;
import org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilsKt;
import org.jetbrains.kotlin.resolve.calls.model.DataFlowInfoForArgumentsImpl;
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallKind;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.tower.NewResolutionOldInferenceKt;
import org.jetbrains.kotlin.resolve.calls.util.CallResolverUtilKt;
import org.jetbrains.kotlin.resolve.calls.util.ResolveArgumentsMode;
@@ -47,7 +43,6 @@ import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
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.types.KotlinType;
import org.jetbrains.kotlin.types.KotlinTypeKt;
import org.jetbrains.kotlin.types.TypeSubstitutor;
@@ -272,7 +267,6 @@ public class CallResolver {
callResolutionContext,
functionDescriptors,
TracingStrategyImpl.create(expression, call),
KotlinCallKind.FUNCTION,
null,
null
);
@@ -285,35 +279,6 @@ public class CallResolver {
return resolutionResults;
}
public OverloadResolutionResults<FunctionDescriptor> resolveSetterCall(
@NotNull ExpressionTypingContext context,
@NotNull ResolvedCall<?> propertyResolvedCall,
@NotNull PropertySetterDescriptor descriptor
) {
KtReferenceExpression propertyElement = (KtReferenceExpression)propertyResolvedCall.getCall().getCallElement();
KtOperationExpression setterCall = PsiUtilsKt.getParentOfTypes(propertyElement, true, KtOperationExpression.class);
assert setterCall != null;
ReceiverParameterDescriptor receiverDescriptor = descriptor.getDispatchReceiverParameter();
ReceiverValue dispatchReceiver = receiverDescriptor != null ? receiverDescriptor.getValue() : null;
Call call = CallMaker.makeCallWithExpressions(propertyElement, null, null, propertyElement, Collections.emptyList(), Call.CallType.DEFAULT);
BasicCallResolutionContext callResolutionContext = BasicCallResolutionContext.create(
context, call, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS,
new DataFlowInfoForArgumentsImpl(propertyResolvedCall.getDataFlowInfoForArguments().getResultInfo(), call)
);
return PSICallResolver.runResolutionAndInferenceForGivenDescriptors(
callResolutionContext,
Collections.singletonList(descriptor),
TracingStrategy.EMPTY,
KotlinCallKind.VARIABLE,
null,
dispatchReceiver != null ? NewResolutionOldInferenceKt.transformToReceiverWithSmartCastInfo(context, dispatchReceiver) : null
);
}
@NotNull
public OverloadResolutionResults<FunctionDescriptor> resolveEqualsCallWithGivenDescriptors(
@NotNull ExpressionTypingContext context,
@@ -328,7 +293,6 @@ public class CallResolver {
callResolutionContext,
functionDescriptors,
TracingStrategyImpl.create(expression, call),
KotlinCallKind.FUNCTION,
null,
NewResolutionOldInferenceKt.transformToReceiverWithSmartCastInfo(context, receiver)
);
@@ -358,7 +322,6 @@ public class CallResolver {
callResolutionContext,
Collections.singletonList(descriptor),
tracingStrategy,
KotlinCallKind.FUNCTION,
substitutor,
null
);
@@ -148,20 +148,19 @@ class PSICallResolver(
context: BasicCallResolutionContext,
descriptors: Collection<CallableDescriptor>,
tracingStrategy: TracingStrategy,
kind: KotlinCallKind,
substitutor: TypeSubstitutor? = null,
dispatchReceiver: ReceiverValueWithSmartCastInfo? = null
receiver: ReceiverValueWithSmartCastInfo? = null
): OverloadResolutionResults<D> {
val isSpecialFunction = descriptors.any { it.name in SPECIAL_FUNCTION_NAMES }
val kotlinCall = toKotlinCall(
context, kind, context.call, givenCandidatesName, tracingStrategy, isSpecialFunction, dispatchReceiver?.receiverValue
context, KotlinCallKind.FUNCTION, context.call, givenCandidatesName, tracingStrategy, isSpecialFunction, receiver?.receiverValue
)
val scopeTower = ASTScopeTower(context)
val resolutionCallbacks = createResolutionCallbacks(context)
val givenCandidates = descriptors.map {
GivenCandidate(
it,
dispatchReceiver = dispatchReceiver,
dispatchReceiver = receiver,
knownTypeParametersResultingSubstitutor = substitutor
)
}
@@ -294,10 +293,6 @@ class PSICallResolver(
return SingleOverloadResolutionResult(resolvedCall)
}
private fun needToReportUnresolvedReferenceForNoneCandidates(call: Call): Boolean =
// Don't report unresolved reference on constructor calls since they are processed separately, and aother error is reported
call.callElement !is KtConstructorDelegationCall
private fun <D : CallableDescriptor> handleErrorResolutionResult(
context: BasicCallResolutionContext,
trace: BindingTrace,
@@ -309,9 +304,7 @@ class PSICallResolver(
diagnostics.firstIsInstanceOrNull<NoneCandidatesCallDiagnostic>()?.let {
kotlinToResolvedCallTransformer.transformAndReport<D>(result, context, tracingStrategy)
if (needToReportUnresolvedReferenceForNoneCandidates(context.call)) {
tracingStrategy.unresolvedReference(trace)
}
tracingStrategy.unresolvedReference(trace)
return OverloadResolutionResultsImpl.nameNotFound()
}
@@ -340,7 +340,6 @@ fun resolveConstructorCallWithGivenDescriptors(
context,
constructors,
tracingStrategy,
KotlinCallKind.FUNCTION,
knownSubstitutor,
receiver?.let { context.transformToReceiverWithSmartCastInfo(it) }
)
@@ -49,13 +49,16 @@ import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver;
import org.jetbrains.kotlin.resolve.calls.CallExpressionResolver;
import org.jetbrains.kotlin.resolve.calls.checkers.*;
import org.jetbrains.kotlin.resolve.calls.inference.BuilderInferenceSession;
import org.jetbrains.kotlin.resolve.calls.model.DataFlowInfoForArgumentsImpl;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallImpl;
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsImpl;
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue;
import org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability;
import org.jetbrains.kotlin.resolve.calls.tasks.OldResolutionCandidate;
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
import org.jetbrains.kotlin.resolve.calls.tower.NewAbstractResolvedCall;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
@@ -996,15 +999,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(expressionWithParenthesis, context.trace.getBindingContext());
assert resolvedCall != null
: "Call is not resolved for property setter: " + PsiUtilsKt.getElementTextWithContext(expressionWithParenthesis);
OverloadResolutionResults<FunctionDescriptor> results =
components.callResolver.resolveSetterCall(context.replaceBindingTrace(trace), resolvedCall, setter);
if (!results.isSuccess()) {
result = false;
if (results.isNothing()) {
KtReferenceExpression propertyElement = (KtReferenceExpression)resolvedCall.getCall().getCallElement();
context.trace.report(UNRESOLVED_REFERENCE.on(propertyElement, propertyElement));
}
}
checkPropertySetterCall(context.replaceBindingTrace(trace), setter, resolvedCall, reportOn);
}
}
@@ -1019,6 +1014,45 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return result;
}
private void checkPropertySetterCall(
@NotNull ExpressionTypingContext context,
@NotNull PropertySetterDescriptor descriptor,
@NotNull ResolvedCall<?> propertyResolvedCall,
@NotNull KtExpression expression
) {
Call call = propertyResolvedCall.getCall();
OldResolutionCandidate<PropertySetterDescriptor> resolutionCandidate = OldResolutionCandidate.create(
call, descriptor, propertyResolvedCall.getDispatchReceiver(), propertyResolvedCall.getExplicitReceiverKind(), null
);
ResolvedCallImpl<PropertySetterDescriptor> resolvedCall = ResolvedCallImpl.create(
resolutionCandidate,
TemporaryBindingTrace.create(context.trace, "Trace for fake property setter resolved call"),
TracingStrategy.EMPTY,
new DataFlowInfoForArgumentsImpl(propertyResolvedCall.getDataFlowInfoForArguments().getResultInfo(), call)
);
resolvedCall.markCallAsCompleted();
if (context.trace.wantsDiagnostics()) {
CallCheckerContext callCheckerContext =
createCallCheckerContext(context);
for (CallChecker checker : components.callCheckers) {
checker.check(resolvedCall, expression, callCheckerContext);
}
}
}
@NotNull
private CallCheckerContext createCallCheckerContext(@NotNull ExpressionTypingContext context) {
return new CallCheckerContext(
context,
components.deprecationResolver,
components.moduleDescriptor,
components.missingSupertypesResolver
);
}
@Override
public KotlinTypeInfo visitBinaryExpression(@NotNull KtBinaryExpression expression, ExpressionTypingContext contextWithExpectedType) {
ExpressionTypingContext context = isBinaryExpressionDependentOnExpectedType(expression)
@@ -95,7 +95,6 @@ fun PsiElement.nextLeaf(filter: (PsiElement) -> Boolean): PsiElement? {
return leaf
}
@SafeVarargs
fun <T : PsiElement> PsiElement.getParentOfTypes(strict: Boolean = false, vararg parentClasses: Class<out T>): T? {
return getParentOfTypesAndPredicate(strict, *parentClasses) { true }
}
@@ -44,9 +44,9 @@ fun test(c: C) {
<!DEPRECATION_ERROR!>v3<!> // DEPRECATION_ERROR in FE 1.0, see KT-48799
v3 = ""
v4
<!DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>v4<!> = "" // DEPRECATION_ERROR in FE 1.0, see KT-48799
<!DEPRECATION_ERROR!>v4<!> = "" // DEPRECATION_ERROR in FE 1.0, see KT-48799
<!DEPRECATION_ERROR!>v5<!> // DEPRECATION_ERROR in FE 1.0, see KT-48799
<!DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>v5<!> = "" // DEPRECATION_ERROR in FE 1.0, see KT-48799
<!DEPRECATION_ERROR!>v5<!> = "" // DEPRECATION_ERROR in FE 1.0, see KT-48799
v6
v6 = ""
}
@@ -132,5 +132,5 @@ fun use(
ned.p = 1
diff.<!DEPRECATION!>p<!>
diff.<!DEBUG_INFO_UNRESOLVED_WITH_TARGET, DEPRECATION, UNRESOLVED_REFERENCE!>p<!> = 1
diff.<!DEPRECATION, DEPRECATION_ERROR!>p<!> = 1
}
@@ -132,5 +132,5 @@ fun use(
ned.p = 1
diff.<!DEPRECATION!>p<!>
diff.<!DEBUG_INFO_UNRESOLVED_WITH_TARGET, DEPRECATION, UNRESOLVED_REFERENCE!>p<!> = 1
diff.<!DEPRECATION, DEPRECATION_ERROR!>p<!> = 1
}
@@ -32,9 +32,9 @@ fun test() {
<!DEPRECATION_ERROR!>v3<!>
v3 = ""
v4
<!DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>v4<!> = ""
<!DEPRECATION_ERROR!>v4<!> = ""
<!DEPRECATION_ERROR!>v5<!>
<!DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>v5<!> = ""
<!DEPRECATION_ERROR!>v5<!> = ""
<!UNRESOLVED_REFERENCE!>v6<!>
<!UNRESOLVED_REFERENCE!>v6<!> = ""
}
@@ -35,8 +35,8 @@ fun test() {
bar {
<!DSL_SCOPE_VIOLATION!>a<!> + 1
<!DSL_SCOPE_VIOLATION!>a<!> += <!DSL_SCOPE_VIOLATION!>a<!> + 1
<!DSL_SCOPE_VIOLATION!>a<!>++
<!DSL_SCOPE_VIOLATION, DSL_SCOPE_VIOLATION!>a<!> += <!DSL_SCOPE_VIOLATION!>a<!> + 1
<!DSL_SCOPE_VIOLATION, DSL_SCOPE_VIOLATION!>a<!>++
<!DSL_SCOPE_VIOLATION!>a1<!> + 1
<!DSL_SCOPE_VIOLATION!>a1<!> += <!DSL_SCOPE_VIOLATION!>a1<!> + 1
@@ -2,6 +2,6 @@ class A {
open inner class Inner
class Nested : Inner {
<!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>constructor()<!>
<!INACCESSIBLE_OUTER_CLASS_EXPRESSION!>constructor()<!><!UNRESOLVED_REFERENCE!><!>
}
}
@@ -39,9 +39,9 @@ fun test() {
<!API_NOT_AVAILABLE!>v3<!>
v3 = ""
v4
<!DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>v4<!> = ""
<!API_NOT_AVAILABLE!>v4<!> = ""
<!API_NOT_AVAILABLE!>v5<!>
<!DEBUG_INFO_UNRESOLVED_WITH_TARGET, UNRESOLVED_REFERENCE!>v5<!> = ""
<!API_NOT_AVAILABLE!>v5<!> = ""
<!UNRESOLVED_REFERENCE!>v6<!>
<!UNRESOLVED_REFERENCE!>v6<!> = ""
<!API_NOT_AVAILABLE!>v7<!>