diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt index 4685fb6750d..b2c36c56bcf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallCompleter.kt @@ -53,7 +53,6 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer -import org.jetbrains.kotlin.types.expressions.FakeCallResolver import java.util.* class CallCompleter( @@ -62,7 +61,6 @@ class CallCompleter( private val dataFlowAnalyzer: DataFlowAnalyzer, private val callCheckers: Iterable, private val builtIns: KotlinBuiltIns, - private val fakeCallResolver: FakeCallResolver, private val languageVersionSettings: LanguageVersionSettings, private val compilerConfiguration: CompilerConfiguration ) { @@ -86,7 +84,7 @@ class CallCompleter( temporaryTrace.commit() } - if (resolvedCall != null) { + if (resolvedCall != null && context.trace.wantsDiagnostics()) { val calleeExpression = if (resolvedCall is VariableAsFunctionResolvedCall) resolvedCall.variableCall.call.calleeExpression else @@ -95,10 +93,12 @@ class CallCompleter( if (calleeExpression != null && !calleeExpression.isFakeElement) calleeExpression else resolvedCall.call.callElement - if (context.trace.wantsDiagnostics()) { - val callCheckerContext = CallCheckerContext(context, languageVersionSettings, compilerConfiguration) - for (callChecker in callCheckers) { - callChecker.check(resolvedCall, reportOn, callCheckerContext) + val callCheckerContext = CallCheckerContext(context, languageVersionSettings, compilerConfiguration) + for (callChecker in callCheckers) { + callChecker.check(resolvedCall, reportOn, callCheckerContext) + + if (resolvedCall is VariableAsFunctionResolvedCall) { + callChecker.check(resolvedCall.variableCall, reportOn, callCheckerContext) } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/resolvedCallUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/resolvedCallUtil.kt index 38de9be8519..5ca2099225c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/resolvedCallUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/resolvedCallUtil.kt @@ -17,13 +17,15 @@ package org.jetbrains.kotlin.resolve.calls.resolvedCallUtil import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.KtCallElement +import org.jetbrains.kotlin.psi.KtPsiUtil +import org.jetbrains.kotlin.psi.KtThisExpression +import org.jetbrains.kotlin.psi.ValueArgument import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall import org.jetbrains.kotlin.resolve.calls.context.CallResolutionContext import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall -import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind @@ -74,29 +76,16 @@ fun ResolvedCall<*>.getExplicitReceiverValue(): ReceiverValue? { } } -fun ResolvedCall<*>.getImplicitReceiverValue(): ImplicitReceiver? { - return when (explicitReceiverKind) { - ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> extensionReceiver ?: dispatchReceiver - ExplicitReceiverKind.DISPATCH_RECEIVER -> extensionReceiver - ExplicitReceiverKind.EXTENSION_RECEIVER -> dispatchReceiver - else -> null - } as? ImplicitReceiver -} +fun ResolvedCall<*>.getImplicitReceiverValue(): ImplicitReceiver? = + getImplicitReceivers().firstOrNull() as? ImplicitReceiver -fun ResolvedCall<*>.getImplicitReceivers(): Collection { - if (this is VariableAsFunctionResolvedCall) { - val receivers = variableCall.getImplicitReceivers() + functionCall.getImplicitReceivers() - assert(receivers.size <= 3) { "There are ${receivers.size} for $this call" } - return receivers - } - - return when (explicitReceiverKind) { - ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> listOfNotNull(dispatchReceiver, extensionReceiver) - ExplicitReceiverKind.DISPATCH_RECEIVER -> listOfNotNull(extensionReceiver) - ExplicitReceiverKind.EXTENSION_RECEIVER -> listOfNotNull(dispatchReceiver) - ExplicitReceiverKind.BOTH_RECEIVERS -> emptyList() - } -} +fun ResolvedCall<*>.getImplicitReceivers(): Collection = + when (explicitReceiverKind) { + ExplicitReceiverKind.NO_EXPLICIT_RECEIVER -> listOfNotNull(extensionReceiver, dispatchReceiver) + ExplicitReceiverKind.DISPATCH_RECEIVER -> listOfNotNull(extensionReceiver) + ExplicitReceiverKind.EXTENSION_RECEIVER -> listOfNotNull(dispatchReceiver) + ExplicitReceiverKind.BOTH_RECEIVERS -> emptyList() + } private fun ResolvedCall<*>.hasSafeNullableReceiver(context: CallResolutionContext<*>): Boolean { if (!call.isSafeCall()) return false diff --git a/compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.kt b/compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.kt new file mode 100644 index 00000000000..ab47cb7b253 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.kt @@ -0,0 +1,6 @@ +@Deprecated("No") +val f: () -> Unit = {} + +fun test() { + f() +} diff --git a/compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.txt b/compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.txt new file mode 100644 index 00000000000..1640e89a0d7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.txt @@ -0,0 +1,4 @@ +package + +@kotlin.Deprecated(message = "No") public val f: () -> kotlin.Unit +public fun test(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 295b1c10b76..97f4d76063b 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -6340,6 +6340,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("propertyWithInvoke.kt") + public void testPropertyWithInvoke() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/propertyWithInvoke.kt"); + doTest(fileName); + } + @TestMetadata("typeUsage.kt") public void testTypeUsage() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/typeUsage.kt");