From fb4c256d0865d4ad029205c4e1a2a5c7e3b5c79c Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Thu, 10 Jul 2014 19:00:40 +0400 Subject: [PATCH] Added tests for choosing 'most specific' resolution candidate Fixed test (while resolve with library on android): 'run' resolves to library function --- .../tailRecursion/recursiveCallInLambda.kt | 4 ++-- .../resolve/mostSpecificUninferredParam.kt | 8 +++++++ .../resolve/mostSpecificUninferredParam.txt | 22 +++++++++++++++++++ .../resolve/mostSpecificWithLambda.kt | 6 +++++ .../resolve/mostSpecificWithLambda.txt | 20 +++++++++++++++++ .../calls/ResolvedCallsTestGenerated.java | 21 +++++++++++++++++- 6 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/resolvedCalls/resolve/mostSpecificUninferredParam.kt create mode 100644 compiler/testData/resolvedCalls/resolve/mostSpecificUninferredParam.txt create mode 100644 compiler/testData/resolvedCalls/resolve/mostSpecificWithLambda.kt create mode 100644 compiler/testData/resolvedCalls/resolve/mostSpecificWithLambda.txt diff --git a/compiler/testData/codegen/box/functions/tailRecursion/recursiveCallInLambda.kt b/compiler/testData/codegen/box/functions/tailRecursion/recursiveCallInLambda.kt index 422062e7ad1..f46d34487a8 100644 --- a/compiler/testData/codegen/box/functions/tailRecursion/recursiveCallInLambda.kt +++ b/compiler/testData/codegen/box/functions/tailRecursion/recursiveCallInLambda.kt @@ -1,11 +1,11 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER tailRecursive fun foo() { - run { + bar { foo() } } -fun run(a: Any) {} +fun bar(a: Any) {} fun box(): String { foo() diff --git a/compiler/testData/resolvedCalls/resolve/mostSpecificUninferredParam.kt b/compiler/testData/resolvedCalls/resolve/mostSpecificUninferredParam.kt new file mode 100644 index 00000000000..1bee99680d1 --- /dev/null +++ b/compiler/testData/resolvedCalls/resolve/mostSpecificUninferredParam.kt @@ -0,0 +1,8 @@ +fun emptyList(): List = throw Exception() + +fun doSmth(l: List) {} +fun doSmth(a: Any) {} + +fun bar() { + doSmth(emptyList()) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/resolve/mostSpecificUninferredParam.txt b/compiler/testData/resolvedCalls/resolve/mostSpecificUninferredParam.txt new file mode 100644 index 00000000000..31c8cbcd687 --- /dev/null +++ b/compiler/testData/resolvedCalls/resolve/mostSpecificUninferredParam.txt @@ -0,0 +1,22 @@ +fun emptyList(): List = throw Exception() + +fun doSmth(l: List) {} +fun doSmth(a: Any) {} + +fun bar() { + doSmth(emptyList()) +} + + +Resolved call: + +Candidate descriptor: fun doSmth(l: List): Unit +Resulting descriptor: fun doSmth(l: List): Unit + +Explicit receiver kind = NO_EXPLICIT_RECEIVER +This object = NO_RECEIVER +Receiver argument = NO_RECEIVER + +Value arguments mapping: + +MATCH_MODULO_UNINFERRED_TYPES l : List = emptyList() \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/resolve/mostSpecificWithLambda.kt b/compiler/testData/resolvedCalls/resolve/mostSpecificWithLambda.kt new file mode 100644 index 00000000000..bc8f2fc1b1c --- /dev/null +++ b/compiler/testData/resolvedCalls/resolve/mostSpecificWithLambda.kt @@ -0,0 +1,6 @@ +fun foo() { + bar { } +} + +fun bar(a: Any) = a +fun bar(f: () -> T): T = f() diff --git a/compiler/testData/resolvedCalls/resolve/mostSpecificWithLambda.txt b/compiler/testData/resolvedCalls/resolve/mostSpecificWithLambda.txt new file mode 100644 index 00000000000..bea03bf1427 --- /dev/null +++ b/compiler/testData/resolvedCalls/resolve/mostSpecificWithLambda.txt @@ -0,0 +1,20 @@ +fun foo() { + bar { } +} + +fun bar(a: Any) = a +fun bar(f: () -> T): T = f() + + +Resolved call: + +Candidate descriptor: fun bar(f: () -> T): T +Resulting descriptor: fun bar(f: () -> Unit): Unit + +Explicit receiver kind = NO_EXPLICIT_RECEIVER +This object = NO_RECEIVER +Receiver argument = NO_RECEIVER + +Value arguments mapping: + +SUCCESS f : () -> Unit = { } \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java b/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java index a00b2d2b7cf..4598f73d6c5 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/resolve/calls/ResolvedCallsTestGenerated.java @@ -31,7 +31,7 @@ import org.jetbrains.jet.resolve.calls.AbstractResolvedCallsTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/resolvedCalls") -@InnerTestClasses({ResolvedCallsTestGenerated.Arguments.class, ResolvedCallsTestGenerated.DifferentCallElements.class, ResolvedCallsTestGenerated.FunctionTypes.class, ResolvedCallsTestGenerated.Invoke.class, ResolvedCallsTestGenerated.RealExamples.class, ResolvedCallsTestGenerated.ThisOrSuper.class}) +@InnerTestClasses({ResolvedCallsTestGenerated.Arguments.class, ResolvedCallsTestGenerated.DifferentCallElements.class, ResolvedCallsTestGenerated.FunctionTypes.class, ResolvedCallsTestGenerated.Invoke.class, ResolvedCallsTestGenerated.RealExamples.class, ResolvedCallsTestGenerated.Resolve.class, ResolvedCallsTestGenerated.ThisOrSuper.class}) public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { public void testAllFilesPresentInResolvedCalls() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls"), Pattern.compile("^(.+)\\.kt$"), true); @@ -342,6 +342,24 @@ public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { } + @TestMetadata("compiler/testData/resolvedCalls/resolve") + public static class Resolve extends AbstractResolvedCallsTest { + public void testAllFilesPresentInResolve() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/resolve"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("mostSpecificUninferredParam.kt") + public void testMostSpecificUninferredParam() throws Exception { + doTest("compiler/testData/resolvedCalls/resolve/mostSpecificUninferredParam.kt"); + } + + @TestMetadata("mostSpecificWithLambda.kt") + public void testMostSpecificWithLambda() throws Exception { + doTest("compiler/testData/resolvedCalls/resolve/mostSpecificWithLambda.kt"); + } + + } + @TestMetadata("compiler/testData/resolvedCalls/thisOrSuper") public static class ThisOrSuper extends AbstractResolvedCallsTest { public void testAllFilesPresentInThisOrSuper() throws Exception { @@ -383,6 +401,7 @@ public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { suite.addTestSuite(FunctionTypes.class); suite.addTestSuite(Invoke.class); suite.addTestSuite(RealExamples.class); + suite.addTestSuite(Resolve.class); suite.addTestSuite(ThisOrSuper.class); return suite; }