From 4dff9cf5fca89d0a0b04a08caaa1e91ad915646d Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Thu, 11 Dec 2014 15:53:18 +0300 Subject: [PATCH] Frontend: fixed explicit receiver kind for dynamic call with implicit dispatch receiver. Additionally added tests for other cases. --- .../resolve/calls/tasks/TaskPrioritizer.kt | 12 ++--- .../explicitReceiverIsDispatchReceiver.kt | 3 ++ .../explicitReceiverIsDispatchReceiver.txt | 12 +++++ .../explicitReceiverIsExtensionReceiver.kt | 5 ++ .../explicitReceiverIsExtensionReceiver.txt | 14 ++++++ .../hasBothDispatchAndExtensionReceivers.kt | 9 ++++ .../hasBothDispatchAndExtensionReceivers.txt | 18 +++++++ ...tensionReceiversWithoutExplicitReceiver.kt | 11 +++++ ...ensionReceiversWithoutExplicitReceiver.txt | 20 ++++++++ .../implicitReceiverIsDispatchReceiver.kt | 3 ++ .../implicitReceiverIsDispatchReceiver.txt | 12 +++++ .../implicitReceiverIsExtensionReceiver.kt | 5 ++ .../implicitReceiverIsExtensionReceiver.txt | 14 ++++++ .../calls/ResolvedCallsTestGenerated.java | 47 ++++++++++++++++++- 14 files changed, 175 insertions(+), 10 deletions(-) create mode 100644 compiler/testData/resolvedCalls/dynamic/explicitReceiverIsDispatchReceiver.kt create mode 100644 compiler/testData/resolvedCalls/dynamic/explicitReceiverIsDispatchReceiver.txt create mode 100644 compiler/testData/resolvedCalls/dynamic/explicitReceiverIsExtensionReceiver.kt create mode 100644 compiler/testData/resolvedCalls/dynamic/explicitReceiverIsExtensionReceiver.txt create mode 100644 compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceivers.kt create mode 100644 compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceivers.txt create mode 100644 compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceiversWithoutExplicitReceiver.kt create mode 100644 compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceiversWithoutExplicitReceiver.txt create mode 100644 compiler/testData/resolvedCalls/dynamic/implicitReceiverIsDispatchReceiver.kt create mode 100644 compiler/testData/resolvedCalls/dynamic/implicitReceiverIsDispatchReceiver.txt create mode 100644 compiler/testData/resolvedCalls/dynamic/implicitReceiverIsExtensionReceiver.kt create mode 100644 compiler/testData/resolvedCalls/dynamic/implicitReceiverIsExtensionReceiver.txt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.kt index aec155fe3d0..d0ff7622e78 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/TaskPrioritizer.kt @@ -191,17 +191,11 @@ public class TaskPrioritizer(private val storageManager: StorageManager) { c.result.addCandidates { val dynamicScope = DynamicCallableDescriptors.createDynamicDescriptorScope(c.context.call, c.scope.getContainingDeclaration()) - val dynamicDescriptors = ArrayList() - for (collector in c.callableDescriptorCollectors) { - dynamicDescriptors.addAll(collector.getNonExtensionsByName(dynamicScope, c.name, c.context.trace)) + val dynamicDescriptors = c.callableDescriptorCollectors.flatMap { + it.getNonExtensionsByName(dynamicScope, c.name, c.context.trace) } - dynamicDescriptors.map { - val dynamicCandidate = ResolutionCandidate.create(c.context.call, it) - dynamicCandidate.setDispatchReceiver(explicitReceiver) - dynamicCandidate.setExplicitReceiverKind(DISPATCH_RECEIVER) - dynamicCandidate - } + convertWithReceivers(dynamicDescriptors, explicitReceiver, NO_RECEIVER, createKind(DISPATCH_RECEIVER, isExplicit), c.context.call) } } diff --git a/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsDispatchReceiver.kt b/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsDispatchReceiver.kt new file mode 100644 index 00000000000..0e181b2786a --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsDispatchReceiver.kt @@ -0,0 +1,3 @@ +fun bar(a: dynamic ) { + a.foo() +} diff --git a/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsDispatchReceiver.txt b/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsDispatchReceiver.txt new file mode 100644 index 00000000000..6cac7721f52 --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsDispatchReceiver.txt @@ -0,0 +1,12 @@ +fun bar(a: dynamic ) { + a.foo() +} + + +Resolved call: + +Resulting descriptor: fun foo(): dynamic defined in bar + +Explicit receiver kind = DISPATCH_RECEIVER +Dispatch receiver = a {('Nothing'..'Any?')} +Extension receiver = NO_RECEIVER diff --git a/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsExtensionReceiver.kt b/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsExtensionReceiver.kt new file mode 100644 index 00000000000..735ce3d1c99 --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsExtensionReceiver.kt @@ -0,0 +1,5 @@ +fun dynamic.foo() {} + +fun bar(a: dynamic) { + a.foo() +} diff --git a/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsExtensionReceiver.txt b/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsExtensionReceiver.txt new file mode 100644 index 00000000000..0b4869bf6a4 --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/explicitReceiverIsExtensionReceiver.txt @@ -0,0 +1,14 @@ +fun dynamic.foo() {} + +fun bar(a: dynamic) { + a.foo() +} + + +Resolved call: + +Resulting descriptor: fun dynamic.foo(): Unit defined in root package + +Explicit receiver kind = EXTENSION_RECEIVER +Dispatch receiver = NO_RECEIVER +Extension receiver = a {('Nothing'..'Any?')} diff --git a/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceivers.kt b/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceivers.kt new file mode 100644 index 00000000000..fd92a6b47f3 --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceivers.kt @@ -0,0 +1,9 @@ +class A { + fun dynamic.foo() {} +} + +fun bar(a: A, b: dynamic) { + with (a) { + b.foo() + } +} diff --git a/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceivers.txt b/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceivers.txt new file mode 100644 index 00000000000..14a46df61dd --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceivers.txt @@ -0,0 +1,18 @@ +class A { + fun dynamic.foo() {} +} + +fun bar(a: A, b: dynamic) { + with (a) { + b.foo() + } +} + + +Resolved call: + +Resulting descriptor: fun dynamic.foo(): Unit defined in A + +Explicit receiver kind = EXTENSION_RECEIVER +Dispatch receiver = AExt{fun A.(): Unit defined in bar} +Extension receiver = b {('Nothing'..'Any?')} diff --git a/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceiversWithoutExplicitReceiver.kt b/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceiversWithoutExplicitReceiver.kt new file mode 100644 index 00000000000..a98d369b38e --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceiversWithoutExplicitReceiver.kt @@ -0,0 +1,11 @@ +class A { + fun dynamic.foo() {} +} + +fun bar(a: A, b: dynamic) { + with (a) { + with (b) { + foo() + } + } +} diff --git a/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceiversWithoutExplicitReceiver.txt b/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceiversWithoutExplicitReceiver.txt new file mode 100644 index 00000000000..6894c7bf701 --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceiversWithoutExplicitReceiver.txt @@ -0,0 +1,20 @@ +class A { + fun dynamic.foo() {} +} + +fun bar(a: A, b: dynamic) { + with (a) { + with (b) { + foo() + } + } +} + + +Resolved call: + +Resulting descriptor: fun dynamic.foo(): Unit defined in A + +Explicit receiver kind = NO_EXPLICIT_RECEIVER +Dispatch receiver = AExt{fun A.(): Unit defined in bar} +Extension receiver = ('Nothing'..'Any?')Ext{fun dynamic.(): Unit defined in bar.} diff --git a/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsDispatchReceiver.kt b/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsDispatchReceiver.kt new file mode 100644 index 00000000000..207ad5e6a02 --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsDispatchReceiver.kt @@ -0,0 +1,3 @@ +fun dynamic.bar() { + foo() +} diff --git a/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsDispatchReceiver.txt b/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsDispatchReceiver.txt new file mode 100644 index 00000000000..105c378ab38 --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsDispatchReceiver.txt @@ -0,0 +1,12 @@ +fun dynamic.bar() { + foo() +} + + +Resolved call: + +Resulting descriptor: fun foo(): dynamic defined in bar + +Explicit receiver kind = NO_EXPLICIT_RECEIVER +Dispatch receiver = ('Nothing'..'Any?')Ext{fun dynamic.bar(): Unit defined in root package} +Extension receiver = NO_RECEIVER diff --git a/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsExtensionReceiver.kt b/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsExtensionReceiver.kt new file mode 100644 index 00000000000..0b8ae6b773e --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsExtensionReceiver.kt @@ -0,0 +1,5 @@ +fun dynamic.foo() {} + +fun dynamic.bar() { + foo() +} diff --git a/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsExtensionReceiver.txt b/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsExtensionReceiver.txt new file mode 100644 index 00000000000..458f974a8a6 --- /dev/null +++ b/compiler/testData/resolvedCalls/dynamic/implicitReceiverIsExtensionReceiver.txt @@ -0,0 +1,14 @@ +fun dynamic.foo() {} + +fun dynamic.bar() { + foo() +} + + +Resolved call: + +Resulting descriptor: fun dynamic.foo(): Unit defined in root package + +Explicit receiver kind = NO_EXPLICIT_RECEIVER +Dispatch receiver = NO_RECEIVER +Extension receiver = ('Nothing'..'Any?')Ext{fun dynamic.bar(): Unit defined in root package} diff --git a/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java b/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java index 7c21dd2c000..754d0f854a7 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java @@ -30,7 +30,7 @@ import java.util.regex.Pattern; @SuppressWarnings("all") @TestMetadata("compiler/testData/resolvedCalls") @TestDataPath("$PROJECT_ROOT") -@InnerTestClasses({ResolvedCallsTestGenerated.Arguments.class, ResolvedCallsTestGenerated.DifferentCallElements.class, ResolvedCallsTestGenerated.FunctionTypes.class, ResolvedCallsTestGenerated.Invoke.class, ResolvedCallsTestGenerated.ObjectsAndClassObjects.class, ResolvedCallsTestGenerated.RealExamples.class, ResolvedCallsTestGenerated.Resolve.class, ResolvedCallsTestGenerated.ThisOrSuper.class}) +@InnerTestClasses({ResolvedCallsTestGenerated.Arguments.class, ResolvedCallsTestGenerated.DifferentCallElements.class, ResolvedCallsTestGenerated.Dynamic.class, ResolvedCallsTestGenerated.FunctionTypes.class, ResolvedCallsTestGenerated.Invoke.class, ResolvedCallsTestGenerated.ObjectsAndClassObjects.class, ResolvedCallsTestGenerated.RealExamples.class, ResolvedCallsTestGenerated.Resolve.class, ResolvedCallsTestGenerated.ThisOrSuper.class}) @RunWith(JUnit3RunnerWithInners.class) public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { public void testAllFilesPresentInResolvedCalls() throws Exception { @@ -290,6 +290,51 @@ public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { } } + @TestMetadata("compiler/testData/resolvedCalls/dynamic") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Dynamic extends AbstractResolvedCallsTest { + public void testAllFilesPresentInDynamic() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/resolvedCalls/dynamic"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("explicitReceiverIsDispatchReceiver.kt") + public void testExplicitReceiverIsDispatchReceiver() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolvedCalls/dynamic/explicitReceiverIsDispatchReceiver.kt"); + doTest(fileName); + } + + @TestMetadata("explicitReceiverIsExtensionReceiver.kt") + public void testExplicitReceiverIsExtensionReceiver() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolvedCalls/dynamic/explicitReceiverIsExtensionReceiver.kt"); + doTest(fileName); + } + + @TestMetadata("hasBothDispatchAndExtensionReceivers.kt") + public void testHasBothDispatchAndExtensionReceivers() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceivers.kt"); + doTest(fileName); + } + + @TestMetadata("hasBothDispatchAndExtensionReceiversWithoutExplicitReceiver.kt") + public void testHasBothDispatchAndExtensionReceiversWithoutExplicitReceiver() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolvedCalls/dynamic/hasBothDispatchAndExtensionReceiversWithoutExplicitReceiver.kt"); + doTest(fileName); + } + + @TestMetadata("implicitReceiverIsDispatchReceiver.kt") + public void testImplicitReceiverIsDispatchReceiver() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolvedCalls/dynamic/implicitReceiverIsDispatchReceiver.kt"); + doTest(fileName); + } + + @TestMetadata("implicitReceiverIsExtensionReceiver.kt") + public void testImplicitReceiverIsExtensionReceiver() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/resolvedCalls/dynamic/implicitReceiverIsExtensionReceiver.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/resolvedCalls/functionTypes") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)