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)