From 857aa76cffa9145507fe086fc585ca8f83a1bc61 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 5 May 2014 11:27:12 +0400 Subject: [PATCH] Added tests for argument mapping --- .../jet/lang/resolve/calls/CallCompleter.kt | 6 +- .../resolve/calls/util/resolvedCallUtil.kt | 10 ++ .../functionLiterals/chainedLambdas.kt | 12 ++ .../notInferredLambdaReturnType.kt | 10 ++ .../functionLiterals/notInferredLambdaType.kt | 10 ++ .../functionLiterals/simpleGenericLambda.kt | 10 ++ .../functionLiterals/simpleLambda.kt | 10 ++ .../functionLiterals/unmappedLambda.kt | 9 + .../genericCalls/inferredParameter.kt | 12 ++ .../arguments/genericCalls/simpleGeneric.kt | 11 ++ .../genericCalls/uninferredParameter.kt | 12 ++ .../uninferredParameterTypeMismatch.kt | 9 + .../namedArguments/positionedAfterNamed.kt | 13 ++ .../namedArguments/shiftedArgsMatch.kt | 13 ++ .../oneArgument/argumentHasNoType.kt | 11 ++ .../arguments/oneArgument/simpleMatch.kt | 11 ++ .../arguments/oneArgument/typeMismatch.kt | 11 ++ .../arguments/oneArgument/unmappedArgument.kt | 9 + .../arguments/realExamples/emptyList.kt | 13 ++ .../realExamples/emptyMutableList.kt | 13 ++ .../severalCandidates/mostSpecific.kt | 14 ++ .../calls/AbstractResolvedCallsTest.kt | 65 ++++++- .../calls/ResolvedCallsTestGenerated.java | 166 +++++++++++++++++- 23 files changed, 451 insertions(+), 9 deletions(-) create mode 100644 compiler/testData/resolvedCalls/arguments/functionLiterals/chainedLambdas.kt create mode 100644 compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaReturnType.kt create mode 100644 compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaType.kt create mode 100644 compiler/testData/resolvedCalls/arguments/functionLiterals/simpleGenericLambda.kt create mode 100644 compiler/testData/resolvedCalls/arguments/functionLiterals/simpleLambda.kt create mode 100644 compiler/testData/resolvedCalls/arguments/functionLiterals/unmappedLambda.kt create mode 100644 compiler/testData/resolvedCalls/arguments/genericCalls/inferredParameter.kt create mode 100644 compiler/testData/resolvedCalls/arguments/genericCalls/simpleGeneric.kt create mode 100644 compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameter.kt create mode 100644 compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameterTypeMismatch.kt create mode 100644 compiler/testData/resolvedCalls/arguments/namedArguments/positionedAfterNamed.kt create mode 100644 compiler/testData/resolvedCalls/arguments/namedArguments/shiftedArgsMatch.kt create mode 100644 compiler/testData/resolvedCalls/arguments/oneArgument/argumentHasNoType.kt create mode 100644 compiler/testData/resolvedCalls/arguments/oneArgument/simpleMatch.kt create mode 100644 compiler/testData/resolvedCalls/arguments/oneArgument/typeMismatch.kt create mode 100644 compiler/testData/resolvedCalls/arguments/oneArgument/unmappedArgument.kt create mode 100644 compiler/testData/resolvedCalls/arguments/realExamples/emptyList.kt create mode 100644 compiler/testData/resolvedCalls/arguments/realExamples/emptyMutableList.kt create mode 100644 compiler/testData/resolvedCalls/arguments/severalCandidates/mostSpecific.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt index f6a8c1224ae..a9ddcc01721 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallCompleter.kt @@ -58,6 +58,7 @@ import org.jetbrains.jet.lang.resolve.bindingContextUtil.getCorrespondingCall import org.jetbrains.jet.lang.psi.JetSafeQualifiedExpression import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace +import org.jetbrains.jet.lang.resolve.calls.util.getAllValueArguments public class CallCompleter( val argumentTypeResolver: ArgumentTypeResolver, @@ -203,11 +204,10 @@ public class CallCompleter( getDataFlowInfoForArgument = { context.dataFlowInfo } } - val arguments = ArrayList(context.call.getValueArguments()) - arguments.addAll(context.call.getFunctionLiteralArguments().map { functionLiteral -> CallMaker.makeValueArgument(functionLiteral) }) + val arguments = context.call.getAllValueArguments() for (valueArgument in arguments) { - val argumentMapping = getArgumentMapping(valueArgument!!) + val argumentMapping = getArgumentMapping(valueArgument) val expectedType = when (argumentMapping) { is ArgumentMatch -> CandidateResolver.getEffectiveExpectedType(argumentMapping.valueParameter, valueArgument) else -> TypeUtils.NO_EXPECTED_TYPE diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/util/resolvedCallUtil.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/util/resolvedCallUtil.kt index 29e97b97d80..d43fd4b2e32 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/util/resolvedCallUtil.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/util/resolvedCallUtil.kt @@ -25,6 +25,9 @@ import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMapping import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMatch import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMatchStatus +import java.util.ArrayList +import org.jetbrains.jet.lang.psi.Call +import org.jetbrains.jet.lang.psi.ValueArgument public fun ResolvedCall.noErrorsInValueArguments(): Boolean { return getCall().getValueArguments().all { argument -> !getArgumentMapping(argument!!).isError() } @@ -54,3 +57,10 @@ fun ResolvedCall.isDirty(): Boolean { argumentMapping is ArgumentMatch && argumentMapping.status == ArgumentMatchStatus.ARGUMENT_HAS_NO_TYPE } } + +fun Call.getAllValueArguments(): List { + val arguments = getValueArguments() + + getFunctionLiteralArguments().map { functionLiteral -> CallMaker.makeValueArgument(functionLiteral) } + [suppress("UNCHECKED_CAST")] + return arguments as List +} diff --git a/compiler/testData/resolvedCalls/arguments/functionLiterals/chainedLambdas.kt b/compiler/testData/resolvedCalls/arguments/functionLiterals/chainedLambdas.kt new file mode 100644 index 00000000000..e5a795e1860 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/functionLiterals/chainedLambdas.kt @@ -0,0 +1,12 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: ArgumentMatch(t : Int, SUCCESS) +// !ARG_2: ArgumentMatch(f : (Int) -> String, SUCCESS) +// !ARG_3: ArgumentMatch(g : (String) -> Int, SUCCESS) + +fun foo(t: T, f: (T) -> S, g: (S) -> R) {} + + +fun test() { + foo(1, { x -> "$x"}, { y -> y.length }) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaReturnType.kt b/compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaReturnType.kt new file mode 100644 index 00000000000..9c099c4a64b --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaReturnType.kt @@ -0,0 +1,10 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: ArgumentMatch(f : () -> ???, SUCCESS) + +fun foo(f: () -> T) {} + + +fun test() { + foo { b } +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaType.kt b/compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaType.kt new file mode 100644 index 00000000000..ee98ffc2057 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaType.kt @@ -0,0 +1,10 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: ArgumentMatch(f : (???) -> String, SUCCESS) + +fun foo(f: (T) -> String) {} + + +fun test() { + foo { x -> "$x"} +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/functionLiterals/simpleGenericLambda.kt b/compiler/testData/resolvedCalls/arguments/functionLiterals/simpleGenericLambda.kt new file mode 100644 index 00000000000..d41b9183940 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/functionLiterals/simpleGenericLambda.kt @@ -0,0 +1,10 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: ArgumentMatch(f : (Int) -> String, SUCCESS) + +fun foo(f: (T) -> String) {} + + +fun test() { + foo { (x: Int) -> "$x"} +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/functionLiterals/simpleLambda.kt b/compiler/testData/resolvedCalls/arguments/functionLiterals/simpleLambda.kt new file mode 100644 index 00000000000..8b0dd255467 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/functionLiterals/simpleLambda.kt @@ -0,0 +1,10 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: ArgumentMatch(f : (Int) -> String, SUCCESS) + +fun foo(f: (Int) -> String) {} + + +fun test() { + foo { x -> "$x"} +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/functionLiterals/unmappedLambda.kt b/compiler/testData/resolvedCalls/arguments/functionLiterals/unmappedLambda.kt new file mode 100644 index 00000000000..d06718d3308 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/functionLiterals/unmappedLambda.kt @@ -0,0 +1,9 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: ArgumentUnmapped + +fun foo() {} + +fun test() { + foo { x -> "$x"} +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/genericCalls/inferredParameter.kt b/compiler/testData/resolvedCalls/arguments/genericCalls/inferredParameter.kt new file mode 100644 index 00000000000..20dac3b0885 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/genericCalls/inferredParameter.kt @@ -0,0 +1,12 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: 11 = ArgumentMatch(t : Comparable, SUCCESS) +// !ARG_2: ls = ArgumentMatch(l : List>, SUCCESS) + +fun foo(t: T, l: List) {} + +fun use(vararg a: Any?) = a + +fun test(a: Any, ls: List) { + use(foo(11, ls)) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/genericCalls/simpleGeneric.kt b/compiler/testData/resolvedCalls/arguments/genericCalls/simpleGeneric.kt new file mode 100644 index 00000000000..8261fbfe47b --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/genericCalls/simpleGeneric.kt @@ -0,0 +1,11 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: A() = ArgumentMatch(t : A, SUCCESS) + +class A {} + +fun foo(t: T) {} + +fun bar() { + foo(A()) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameter.kt b/compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameter.kt new file mode 100644 index 00000000000..76f91dba915 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameter.kt @@ -0,0 +1,12 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: 11 = ArgumentMatch(t : ???, SUCCESS) +// !ARG_2: ls = ArgumentMatch(l : MutableList, SUCCESS) + +fun foo(t: T, l: MutableList) {} + +fun use(vararg a: Any?) = a + +fun test(ls: MutableList) { + use(foo(11, ls)) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameterTypeMismatch.kt b/compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameterTypeMismatch.kt new file mode 100644 index 00000000000..f858de84dc3 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameterTypeMismatch.kt @@ -0,0 +1,9 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: 11 = ArgumentMatch(l : List, TYPE_MISMATCH) + +fun foo(l: List) {} + +fun test() { + foo(11) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/namedArguments/positionedAfterNamed.kt b/compiler/testData/resolvedCalls/arguments/namedArguments/positionedAfterNamed.kt new file mode 100644 index 00000000000..4837855354b --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/namedArguments/positionedAfterNamed.kt @@ -0,0 +1,13 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: B() = ArgumentMatch(b : B, SUCCESS) +// !ARG_2: A() = ArgumentUnmapped + +class A {} +class B {} + +fun foo(a: A, b: B) {} + +fun bar() { + foo(b = B(), A()) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/namedArguments/shiftedArgsMatch.kt b/compiler/testData/resolvedCalls/arguments/namedArguments/shiftedArgsMatch.kt new file mode 100644 index 00000000000..f14f2b5aea9 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/namedArguments/shiftedArgsMatch.kt @@ -0,0 +1,13 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: B() = ArgumentMatch(b : B, SUCCESS) +// !ARG_2: A() = ArgumentMatch(a : A, SUCCESS) + +class A {} +class B {} + +fun foo(a: A, b: B) {} + +fun bar() { + foo(b = B(), a = A()) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/oneArgument/argumentHasNoType.kt b/compiler/testData/resolvedCalls/arguments/oneArgument/argumentHasNoType.kt new file mode 100644 index 00000000000..4eafe86e688 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/oneArgument/argumentHasNoType.kt @@ -0,0 +1,11 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: b = ArgumentMatch(a : A, ARGUMENT_HAS_NO_TYPE) + +class A {} + +fun foo(a: A) {} + +fun bar() { + foo(b) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/oneArgument/simpleMatch.kt b/compiler/testData/resolvedCalls/arguments/oneArgument/simpleMatch.kt new file mode 100644 index 00000000000..2de151ffeda --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/oneArgument/simpleMatch.kt @@ -0,0 +1,11 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: A() = ArgumentMatch(a : A, SUCCESS) + +class A {} + +fun foo(a: A) {} + +fun bar() { + foo(A()) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/oneArgument/typeMismatch.kt b/compiler/testData/resolvedCalls/arguments/oneArgument/typeMismatch.kt new file mode 100644 index 00000000000..38c0bf6c254 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/oneArgument/typeMismatch.kt @@ -0,0 +1,11 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: "" = ArgumentMatch(a : A, TYPE_MISMATCH) + +class A {} + +fun foo(a: A) {} + +fun bar() { + foo("") +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/oneArgument/unmappedArgument.kt b/compiler/testData/resolvedCalls/arguments/oneArgument/unmappedArgument.kt new file mode 100644 index 00000000000..6a7f2def715 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/oneArgument/unmappedArgument.kt @@ -0,0 +1,9 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: "" = ArgumentUnmapped + +fun foo() {} + +fun bar() { + foo("") +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/realExamples/emptyList.kt b/compiler/testData/resolvedCalls/arguments/realExamples/emptyList.kt new file mode 100644 index 00000000000..0ee9730aa6f --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/realExamples/emptyList.kt @@ -0,0 +1,13 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: emptyList() = ArgumentMatch(t : List, SUCCESS) + +class A {} + +fun foo(t: T) {} + +fun emptyList(): List = throw Exception() + +fun bar() { + foo(emptyList()) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/realExamples/emptyMutableList.kt b/compiler/testData/resolvedCalls/arguments/realExamples/emptyMutableList.kt new file mode 100644 index 00000000000..833ae06bb32 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/realExamples/emptyMutableList.kt @@ -0,0 +1,13 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: emptyList() = ArgumentMatch(t : MutableList, SUCCESS) + +class A {} + +fun foo(t: T) {} + +fun emptyList(): MutableList = throw Exception() + +fun bar() { + foo(emptyList()) +} \ No newline at end of file diff --git a/compiler/testData/resolvedCalls/arguments/severalCandidates/mostSpecific.kt b/compiler/testData/resolvedCalls/arguments/severalCandidates/mostSpecific.kt new file mode 100644 index 00000000000..2c65f7e1949 --- /dev/null +++ b/compiler/testData/resolvedCalls/arguments/severalCandidates/mostSpecific.kt @@ -0,0 +1,14 @@ +// !ONLY_ARGUMENTS +// !CALL: foo +// !ARG_1: A() = ArgumentMatch(a : A, SUCCESS) +// !ARG_2: "" = ArgumentMatch(s : String, SUCCESS) + +class A {} + +fun foo(a: A) {} +fun foo(a: A, s: String) {} +fun foo(a: A, any: Any) {} + +fun bar() { + foo(A(), "") +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/resolve/calls/AbstractResolvedCallsTest.kt b/compiler/tests/org/jetbrains/jet/resolve/calls/AbstractResolvedCallsTest.kt index 1f4cec8c85e..78aef0b7c4d 100644 --- a/compiler/tests/org/jetbrains/jet/resolve/calls/AbstractResolvedCallsTest.kt +++ b/compiler/tests/org/jetbrains/jet/resolve/calls/AbstractResolvedCallsTest.kt @@ -34,6 +34,12 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.jet.lang.resolve.lazy.JvmResolveUtil +import java.util.ArrayList +import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMapping +import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMatch +import org.jetbrains.jet.lang.diagnostics.rendering.Renderers +import org.jetbrains.jet.lang.resolve.calls.util.getAllValueArguments +import org.jetbrains.jet.renderer.DescriptorRenderer public abstract class AbstractResolvedCallsTest() : JetLiteFixture() { override fun createEnvironment(): JetCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY) @@ -43,6 +49,7 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() { val text = JetTestUtils.doLoadFile(file) val directives = JetTestUtils.parseDirectives(text) + val onlyArguments = directives.onlyArguments() val (callName, thisObject, receiverArgument) = with (directives) { Triple(get("CALL"), get("THIS_OBJECT"), get("RECEIVER_ARGUMENT")) } @@ -50,12 +57,14 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() { fun analyzeFileAndGetResolvedCallEntries(): Map> { val psiFile = JetTestUtils.loadJetFile(getProject(), file)!! - val analyzeExhaust = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile) + val analyzeExhaust = JvmResolveUtil.analyzeOneFileWithJavaIntegration(psiFile) val bindingContext = analyzeExhaust.getBindingContext() return bindingContext.getSliceContents(BindingContext.RESOLVED_CALL) } fun checkResolvedCall(resolvedCall: ResolvedCall<*>, element: JetElement) { + if (onlyArguments) return + val lineAndColumn = DiagnosticUtils.getLineAndColumnInPsiFile(element.getContainingFile(), element.getTextRange()) val (actualThisObject, actualReceiverArgument, actualExplicitReceiverKind) = with(resolvedCall) { @@ -66,10 +75,26 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() { assertEquals(thisObject, actualThisObject, "${actualDataMessage}This object mismatch: ") assertEquals(receiverArgument, actualReceiverArgument, "${actualDataMessage}Receiver argument mismatch: ") - assertEquals(explicitReceiverKind, actualExplicitReceiverKind, "$actualDataMessage" + + assertEquals(explicitReceiverKind, actualExplicitReceiverKind, + "$actualDataMessage" + "Explicit receiver kind for resolved call for '${element.getText()}'$lineAndColumn in not as expected") } + val argumentsExpectedData = directives.getArgumentsExpectedData() + fun checkArguments(resolvedCall: ResolvedCall<*>) { + if (argumentsExpectedData.isEmpty()) return + + for ((index, valueArgument) in resolvedCall.getCall().getAllValueArguments().withIndices()) { + val (argText, argumentMapping) = argumentsExpectedData[index] + if (argText != null) { + assertEquals(argText, valueArgument.getArgumentExpression()!!.getText(), + "An argument expression is incorrect") + } + assertEquals(argumentMapping, resolvedCall.getArgumentMapping(valueArgument).print(), + "Argument mapping is incorrect") + } + } + var callFound = false for ((element, resolvedCall) in analyzeFileAndGetResolvedCallEntries()) { @@ -77,6 +102,7 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() { if (callName == null || callName != actualName) return callFound = true checkResolvedCall(resolvedCall, element) + checkArguments(resolvedCall) } if (resolvedCall is VariableAsFunctionResolvedCall) { @@ -101,11 +127,12 @@ private fun ReceiverValue.getText() = else toString() private val EXPLICIT_RECEIVER_KIND_DIRECTIVE: String = "EXPLICIT_RECEIVER_KIND" -private fun Map.getExplicitReceiverKind(): ExplicitReceiverKind { +private fun Map.getExplicitReceiverKind(): ExplicitReceiverKind? { + if (onlyArguments()) return null + val explicitReceiverKind = get(EXPLICIT_RECEIVER_KIND_DIRECTIVE) assert(explicitReceiverKind != null) { "$EXPLICIT_RECEIVER_KIND_DIRECTIVE should be present." } - try - { + try { return ExplicitReceiverKind.valueOf(explicitReceiverKind!!) } catch (e: IllegalArgumentException) { @@ -117,4 +144,32 @@ private fun Map.getExplicitReceiverKind(): ExplicitReceiverKind message.append("\nnot $explicitReceiverKind.") throw AssertionError(message) } +} + +private fun Map.getArgumentsExpectedData(): List> { + val result = ArrayList>() + for (i in 1..7) { + val argData = get("ARG_$i") + if (argData == null) continue + + if (argData.contains("=")) { + val strings = argData.split("=") + assert(strings.size == 2, "Incorrect input data for an argument ARG_$i : $argData") + result.add(Pair(strings[0].trim(), strings[1].trim())) + } + else { + result.add(Pair(null, argData)) + } + } + return result +} + +private fun Map.onlyArguments() = containsKey("ONLY_ARGUMENTS") + +fun ArgumentMapping.print() = when (this) { + is ArgumentMatch -> { + val parameterType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(valueParameter.getType()) + "ArgumentMatch(${valueParameter.getName()} : ${parameterType}, ${status.name()})" + } + else -> "ArgumentUnmapped" } \ 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 ba2dba441bb..20321fb5d6f 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.FunctionTypes.class, ResolvedCallsTestGenerated.Invoke.class, ResolvedCallsTestGenerated.RealExamples.class}) +@InnerTestClasses({ResolvedCallsTestGenerated.Arguments.class, ResolvedCallsTestGenerated.FunctionTypes.class, ResolvedCallsTestGenerated.Invoke.class, ResolvedCallsTestGenerated.RealExamples.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); @@ -77,6 +77,169 @@ public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { doTest("compiler/testData/resolvedCalls/simpleCall.kt"); } + @TestMetadata("compiler/testData/resolvedCalls/arguments") + @InnerTestClasses({Arguments.FunctionLiterals.class, Arguments.GenericCalls.class, Arguments.NamedArguments.class, Arguments.OneArgument.class, Arguments.RealExamples.class, Arguments.SeveralCandidates.class}) + public static class Arguments extends AbstractResolvedCallsTest { + public void testAllFilesPresentInArguments() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("compiler/testData/resolvedCalls/arguments/functionLiterals") + public static class FunctionLiterals extends AbstractResolvedCallsTest { + public void testAllFilesPresentInFunctionLiterals() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/functionLiterals"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("chainedLambdas.kt") + public void testChainedLambdas() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/chainedLambdas.kt"); + } + + @TestMetadata("notInferredLambdaReturnType.kt") + public void testNotInferredLambdaReturnType() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaReturnType.kt"); + } + + @TestMetadata("notInferredLambdaType.kt") + public void testNotInferredLambdaType() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaType.kt"); + } + + @TestMetadata("simpleGenericLambda.kt") + public void testSimpleGenericLambda() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/simpleGenericLambda.kt"); + } + + @TestMetadata("simpleLambda.kt") + public void testSimpleLambda() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/simpleLambda.kt"); + } + + @TestMetadata("unmappedLambda.kt") + public void testUnmappedLambda() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/unmappedLambda.kt"); + } + + } + + @TestMetadata("compiler/testData/resolvedCalls/arguments/genericCalls") + public static class GenericCalls extends AbstractResolvedCallsTest { + public void testAllFilesPresentInGenericCalls() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/genericCalls"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("inferredParameter.kt") + public void testInferredParameter() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/genericCalls/inferredParameter.kt"); + } + + @TestMetadata("simpleGeneric.kt") + public void testSimpleGeneric() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/genericCalls/simpleGeneric.kt"); + } + + @TestMetadata("uninferredParameter.kt") + public void testUninferredParameter() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameter.kt"); + } + + @TestMetadata("uninferredParameterTypeMismatch.kt") + public void testUninferredParameterTypeMismatch() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameterTypeMismatch.kt"); + } + + } + + @TestMetadata("compiler/testData/resolvedCalls/arguments/namedArguments") + public static class NamedArguments extends AbstractResolvedCallsTest { + public void testAllFilesPresentInNamedArguments() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/namedArguments"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("positionedAfterNamed.kt") + public void testPositionedAfterNamed() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/namedArguments/positionedAfterNamed.kt"); + } + + @TestMetadata("shiftedArgsMatch.kt") + public void testShiftedArgsMatch() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/namedArguments/shiftedArgsMatch.kt"); + } + + } + + @TestMetadata("compiler/testData/resolvedCalls/arguments/oneArgument") + public static class OneArgument extends AbstractResolvedCallsTest { + public void testAllFilesPresentInOneArgument() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/oneArgument"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("argumentHasNoType.kt") + public void testArgumentHasNoType() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/oneArgument/argumentHasNoType.kt"); + } + + @TestMetadata("simpleMatch.kt") + public void testSimpleMatch() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/oneArgument/simpleMatch.kt"); + } + + @TestMetadata("typeMismatch.kt") + public void testTypeMismatch() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/oneArgument/typeMismatch.kt"); + } + + @TestMetadata("unmappedArgument.kt") + public void testUnmappedArgument() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/oneArgument/unmappedArgument.kt"); + } + + } + + @TestMetadata("compiler/testData/resolvedCalls/arguments/realExamples") + public static class RealExamples extends AbstractResolvedCallsTest { + public void testAllFilesPresentInRealExamples() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/realExamples"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("emptyList.kt") + public void testEmptyList() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/realExamples/emptyList.kt"); + } + + @TestMetadata("emptyMutableList.kt") + public void testEmptyMutableList() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/realExamples/emptyMutableList.kt"); + } + + } + + @TestMetadata("compiler/testData/resolvedCalls/arguments/severalCandidates") + public static class SeveralCandidates extends AbstractResolvedCallsTest { + public void testAllFilesPresentInSeveralCandidates() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/severalCandidates"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("mostSpecific.kt") + public void testMostSpecific() throws Exception { + doTest("compiler/testData/resolvedCalls/arguments/severalCandidates/mostSpecific.kt"); + } + + } + + public static Test innerSuite() { + TestSuite suite = new TestSuite("Arguments"); + suite.addTestSuite(Arguments.class); + suite.addTestSuite(FunctionLiterals.class); + suite.addTestSuite(GenericCalls.class); + suite.addTestSuite(NamedArguments.class); + suite.addTestSuite(OneArgument.class); + suite.addTestSuite(RealExamples.class); + suite.addTestSuite(SeveralCandidates.class); + return suite; + } + } + @TestMetadata("compiler/testData/resolvedCalls/functionTypes") public static class FunctionTypes extends AbstractResolvedCallsTest { public void testAllFilesPresentInFunctionTypes() throws Exception { @@ -159,6 +322,7 @@ public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest { public static Test suite() { TestSuite suite = new TestSuite("ResolvedCallsTestGenerated"); suite.addTestSuite(ResolvedCallsTestGenerated.class); + suite.addTest(Arguments.innerSuite()); suite.addTestSuite(FunctionTypes.class); suite.addTestSuite(Invoke.class); suite.addTestSuite(RealExamples.class);