From 4ac3cbc384aa8bcf9f8d39dbc12f09c17e37f07c Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Thu, 11 Dec 2014 19:51:03 +0300 Subject: [PATCH] Frontend: allow omit types in lambda parameters of dynamic calls. --- .../lang/resolve/calls/tasks/dynamicCalls.kt | 22 +++++++++++++++++-- .../dynamicTypes/dynamicCallsWithLambdas.kt | 8 +++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/dynamicCalls.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/dynamicCalls.kt index 58b11c7e2ec..c53e521504b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/dynamicCalls.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/tasks/dynamicCalls.kt @@ -33,7 +33,6 @@ import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl import org.jetbrains.jet.lang.types.Variance import org.jetbrains.jet.lang.resolve.name.Name import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor -import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl import org.jetbrains.jet.lang.types.JetType import kotlin.platform.platformStatic import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver @@ -50,6 +49,10 @@ import org.jetbrains.jet.lexer.JetTokens import org.jetbrains.jet.lang.types.expressions.OperatorConventions import org.jetbrains.jet.lang.psi.JetOperationReferenceExpression import org.jetbrains.jet.lang.resolve.DescriptorFactory +import org.jetbrains.jet.lang.psi.JetFunctionLiteralArgument +import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl +import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns +import org.jetbrains.jet.lang.types.TypeUtils object DynamicCallableDescriptors { @@ -165,13 +168,28 @@ object DynamicCallableDescriptors { private fun createValueParameters(owner: DeclarationDescriptor, call: Call): List = call.getValueArguments().withIndices().map { p -> val (index, arg) = p + + val type = + when (arg) { + is JetFunctionLiteralArgument -> { + val funLiteral = arg.getFunctionLiteral().getFunctionLiteral() + + val receiverType = funLiteral.getReceiverTypeReference()?.let { DynamicType } + val parameterTypes = funLiteral.getValueParameters().map { DynamicType } + + KotlinBuiltIns.getInstance().getFunctionType(Annotations.EMPTY, receiverType, parameterTypes, DynamicType) + } + + else -> DynamicType + } + ValueParameterDescriptorImpl( owner, null, index, Annotations.EMPTY, arg.getArgumentName()?.getReferenceExpression()?.getReferencedNameAsName() ?: Name.identifier("p$index"), - DynamicType, + type, false, null, SourceElement.NO_SOURCE diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt index c411fcd103b..373e35b19a9 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt @@ -3,11 +3,15 @@ fun test(d: dynamic) { d.foo { it } - d.foo { x -> } + d.foo { x -> } d.foo { (x: Int) -> "" } - d.foo { x, y -> "" } + d.foo { x, y -> "" } d.foo { (x: String, y: Int) -> "" } + + d.foo { (x: String, y: Int): Int -> "" } + + d.foo { String.(x: String, y: Int): Int -> length() } }