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 4c56ca7d8f4..ab1b0615d3c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java @@ -20,8 +20,12 @@ 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; @@ -43,6 +47,7 @@ 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; @@ -267,6 +272,7 @@ public class CallResolver { callResolutionContext, functionDescriptors, TracingStrategyImpl.create(expression, call), + KotlinCallKind.FUNCTION, null, null ); @@ -279,6 +285,35 @@ 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, @@ -293,6 +328,7 @@ public class CallResolver { callResolutionContext, functionDescriptors, TracingStrategyImpl.create(expression, call), + KotlinCallKind.FUNCTION, null, NewResolutionOldInferenceKt.transformToReceiverWithSmartCastInfo(context, receiver) ); @@ -322,6 +358,7 @@ 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 6434f47e544..6a996fe8f95 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 @@ -147,19 +147,20 @@ class PSICallResolver( context: BasicCallResolutionContext, descriptors: Collection, tracingStrategy: TracingStrategy, + kind: KotlinCallKind, substitutor: TypeSubstitutor? = null, - receiver: ReceiverValueWithSmartCastInfo? = null + dispatchReceiver: ReceiverValueWithSmartCastInfo? = null ): OverloadResolutionResults { val isSpecialFunction = descriptors.any { it.name in SPECIAL_FUNCTION_NAMES } val kotlinCall = toKotlinCall( - context, KotlinCallKind.FUNCTION, context.call, givenCandidatesName, tracingStrategy, isSpecialFunction, receiver?.receiverValue + context, kind, context.call, givenCandidatesName, tracingStrategy, isSpecialFunction, dispatchReceiver?.receiverValue ) val scopeTower = ASTScopeTower(context) val resolutionCallbacks = createResolutionCallbacks(context) val givenCandidates = descriptors.map { GivenCandidate( it, - dispatchReceiver = receiver, + dispatchReceiver = dispatchReceiver, knownTypeParametersResultingSubstitutor = substitutor ) } @@ -292,6 +293,10 @@ 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, @@ -303,7 +308,9 @@ class PSICallResolver( diagnostics.firstIsInstanceOrNull()?.let { kotlinToResolvedCallTransformer.transformAndReport(result, context, tracingStrategy) - tracingStrategy.unresolvedReference(trace) + if (needToReportUnresolvedReferenceForNoneCandidates(context.call)) { + 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 7cde5004fa2..516038ea2a6 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,6 +340,7 @@ 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 9d0ba324bf7..81f6798f545 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -49,16 +49,13 @@ 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; @@ -999,7 +996,15 @@ 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); - checkPropertySetterCall(context.replaceBindingTrace(trace), setter, resolvedCall, reportOn); + 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)); + } + } } } @@ -1014,45 +1019,6 @@ 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 ca5d168574a..876e12a7356 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt @@ -95,6 +95,7 @@ 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 325e585b60d..fc946d5de0e 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 182584ab6f1..863aeb2a2de 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 575ab135398..717020d28bb 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 a47332edf1c..97bb8f0f48f 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 fbb90904f91..ba521b4d4cd 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 603d71739f1..45dfbf44d3c 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 28bfadf4c27..827420f6753 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