From 39b6637c7cdf8fbbca25cc6f0c727174614625c2 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Fri, 11 Dec 2015 13:55:59 +0300 Subject: [PATCH] Fix exception from InvokeProcessor when we get invoke from extension function type. --- .../resolve/calls/tower/InvokeProcessors.kt | 10 ++++---- .../resolve/invoke/invokeAndSmartCast.kt | 23 +++++++++++++++++++ .../resolve/invoke/invokeAndSmartCast.txt | 12 ++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 +++++ 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.kt create mode 100644 compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt index d38cb737547..957172ce2db 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt @@ -143,13 +143,11 @@ private fun ScopeTower.getExtensionInvokeCandidateDescriptor( ): CandidateWithBoundDispatchReceiver? { if (!KotlinBuiltIns.isExactExtensionFunctionType(extensionFunctionReceiver.type)) return null - return ReceiverScopeTowerLevel(this, extensionFunctionReceiver).getFunctions(OperatorNameConventions.INVOKE, null).single().let { - assert(it.diagnostics.isEmpty()) - val synthesizedInvoke = createSynthesizedInvokes(listOf(it.descriptor)).single() + val invokeDescriptor = extensionFunctionReceiver.type.memberScope.getContributedFunctions(OperatorNameConventions.INVOKE, location).single() + val synthesizedInvoke = createSynthesizedInvokes(listOf(invokeDescriptor)).single() - // here we don't add SynthesizedDescriptor diagnostic because it should has priority as member - CandidateWithBoundDispatchReceiverImpl(extensionFunctionReceiver, synthesizedInvoke, listOf()) - } + // here we don't add SynthesizedDescriptor diagnostic because it should has priority as member + return CandidateWithBoundDispatchReceiverImpl(extensionFunctionReceiver, synthesizedInvoke, listOf()) } // case 1.(foo())() or (foo())() diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.kt new file mode 100644 index 00000000000..09779e354a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.kt @@ -0,0 +1,23 @@ +class A(val x: (String.() -> Unit)?) + +fun test(a: A) { + if (a.x != null) { + "".(a.x)() + a.x("") // todo + (a.x)("") + } + "".(a.x)() + a.x("") + (a.x)("") + + with("") { + a.x() + (a.x)() + if (a.x != null) { + a.x() // todo + (a.x)() + } + } +} + +fun with(receiver: T, f: T.() -> R): R = receiver.f() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.txt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.txt new file mode 100644 index 00000000000..a6fd78c4408 --- /dev/null +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.txt @@ -0,0 +1,12 @@ +package + +public fun test(/*0*/ a: A): kotlin.Unit +public fun with(/*0*/ receiver: T, /*1*/ f: T.() -> R): R + +public final class A { + public constructor A(/*0*/ x: (kotlin.String.() -> kotlin.Unit)?) + public final val x: (kotlin.String.() -> kotlin.Unit)? + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 6373915ca7c..234bbae8034 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -13430,6 +13430,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("invokeAndSmartCast.kt") + public void testInvokeAndSmartCast() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/invokeAndSmartCast.kt"); + doTest(fileName); + } + @TestMetadata("invokeAsExtension.kt") public void testInvokeAsExtension() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/invoke/invokeAsExtension.kt");