diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java index ab1b0615d3c..4c56ca7d8f4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java @@ -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 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 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 ); 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 800ce144fe8..02692695d16 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 @@ -148,20 +148,19 @@ class PSICallResolver( context: BasicCallResolutionContext, descriptors: Collection, tracingStrategy: TracingStrategy, - kind: KotlinCallKind, substitutor: TypeSubstitutor? = null, - dispatchReceiver: ReceiverValueWithSmartCastInfo? = null + receiver: ReceiverValueWithSmartCastInfo? = null ): OverloadResolutionResults { 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 handleErrorResolutionResult( context: BasicCallResolutionContext, trace: BindingTrace, @@ -309,9 +304,7 @@ class PSICallResolver( diagnostics.firstIsInstanceOrNull()?.let { kotlinToResolvedCallTransformer.transformAndReport(result, context, tracingStrategy) - if (needToReportUnresolvedReferenceForNoneCandidates(context.call)) { - tracingStrategy.unresolvedReference(trace) - } + tracingStrategy.unresolvedReference(trace) return OverloadResolutionResultsImpl.nameNotFound() } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/CallResolverUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/CallResolverUtil.kt index 516038ea2a6..7cde5004fa2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/CallResolverUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/CallResolverUtil.kt @@ -340,7 +340,6 @@ fun resolveConstructorCallWithGivenDescriptors( context, constructors, tracingStrategy, - KotlinCallKind.FUNCTION, knownSubstitutor, receiver?.let { context.transformToReceiverWithSmartCastInfo(it) } ) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index 81f6798f545..9d0ba324bf7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -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 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 resolutionCandidate = OldResolutionCandidate.create( + call, descriptor, propertyResolvedCall.getDispatchReceiver(), propertyResolvedCall.getExplicitReceiverKind(), null + ); + + ResolvedCallImpl 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) diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt index 876e12a7356..ca5d168574a 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt @@ -95,7 +95,6 @@ fun PsiElement.nextLeaf(filter: (PsiElement) -> Boolean): PsiElement? { return leaf } -@SafeVarargs fun PsiElement.getParentOfTypes(strict: Boolean = false, vararg parentClasses: Class): T? { return getParentOfTypesAndPredicate(strict, *parentClasses) { true } } diff --git a/compiler/testData/diagnostics/tests/deprecated/candidateBehindHiddenPropertyAccessors.kt b/compiler/testData/diagnostics/tests/deprecated/candidateBehindHiddenPropertyAccessors.kt index fc946d5de0e..325e585b60d 100644 --- a/compiler/testData/diagnostics/tests/deprecated/candidateBehindHiddenPropertyAccessors.kt +++ b/compiler/testData/diagnostics/tests/deprecated/candidateBehindHiddenPropertyAccessors.kt @@ -44,9 +44,9 @@ fun test(c: C) { v3 // DEPRECATION_ERROR in FE 1.0, see KT-48799 v3 = "" v4 - v4 = "" // DEPRECATION_ERROR in FE 1.0, see KT-48799 + v4 = "" // DEPRECATION_ERROR in FE 1.0, see KT-48799 v5 // DEPRECATION_ERROR in FE 1.0, see KT-48799 - v5 = "" // DEPRECATION_ERROR in FE 1.0, see KT-48799 + v5 = "" // DEPRECATION_ERROR in FE 1.0, see KT-48799 v6 v6 = "" } diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance_after.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance_after.kt index 863aeb2a2de..182584ab6f1 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance_after.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance_after.kt @@ -132,5 +132,5 @@ fun use( ned.p = 1 diff.p - diff.p = 1 + diff.p = 1 } diff --git a/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance_before.kt b/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance_before.kt index 717020d28bb..575ab135398 100644 --- a/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance_before.kt +++ b/compiler/testData/diagnostics/tests/deprecated/deprecatedPropertyInheritance_before.kt @@ -132,5 +132,5 @@ fun use( ned.p = 1 diff.p - diff.p = 1 + diff.p = 1 } diff --git a/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.kt b/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.kt index 97bb8f0f48f..a47332edf1c 100644 --- a/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.kt +++ b/compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.kt @@ -32,9 +32,9 @@ fun test() { v3 v3 = "" v4 - v4 = "" + v4 = "" v5 - v5 = "" + v5 = "" v6 v6 = "" } diff --git a/compiler/testData/diagnostics/tests/resolve/dslMarker/properties.kt b/compiler/testData/diagnostics/tests/resolve/dslMarker/properties.kt index ba521b4d4cd..fbb90904f91 100644 --- a/compiler/testData/diagnostics/tests/resolve/dslMarker/properties.kt +++ b/compiler/testData/diagnostics/tests/resolve/dslMarker/properties.kt @@ -35,8 +35,8 @@ fun test() { bar { a + 1 - a += a + 1 - a++ + a += a + 1 + a++ a1 + 1 a1 += a1 + 1 diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.kt index 45dfbf44d3c..603d71739f1 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/nestedExtendsInner.kt @@ -2,6 +2,6 @@ class A { open inner class Inner class Nested : Inner { - constructor() + constructor() } } diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/propertyAccessors.kt b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/propertyAccessors.kt index 827420f6753..28bfadf4c27 100644 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/propertyAccessors.kt +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/apiVersion/propertyAccessors.kt @@ -39,9 +39,9 @@ fun test() { v3 v3 = "" v4 - v4 = "" + v4 = "" v5 - v5 = "" + v5 = "" v6 v6 = "" v7