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 4c4a62258d6..60535588c48 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 @@ -53,6 +53,8 @@ import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns import org.jetbrains.jet.lang.psi.ValueArgument import java.util.ArrayList +import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression +import org.jetbrains.jet.lang.psi.JetPsiUtil object DynamicCallableDescriptors { @@ -185,8 +187,8 @@ object DynamicCallableDescriptors { )) } - fun getFunctionType(arg: JetFunctionLiteralArgument): JetType { - val funLiteral = arg.getFunctionLiteral().getFunctionLiteral() + fun getFunctionType(funLiteralExpr: JetFunctionLiteralExpression): JetType { + val funLiteral = funLiteralExpr.getFunctionLiteral() val receiverType = funLiteral.getReceiverTypeReference()?.let { DynamicType } val parameterTypes = funLiteral.getValueParameters().map { DynamicType } @@ -199,9 +201,11 @@ object DynamicCallableDescriptors { val varargElementType: JetType? var hasSpreadOperator = false + val argExpression = JetPsiUtil.deparenthesize(arg.getArgumentExpression(), false) + when { - arg is JetFunctionLiteralArgument -> { - outType = getFunctionType(arg) + argExpression is JetFunctionLiteralExpression -> { + outType = getFunctionType(argExpression) varargElementType = null } @@ -221,7 +225,7 @@ object DynamicCallableDescriptors { if (hasSpreadOperator) { for (funLiteralArg in call.getFunctionLiteralArguments()) { - addParameter(funLiteralArg, getFunctionType(funLiteralArg), null) + addParameter(funLiteralArg, getFunctionType(funLiteralArg.getFunctionLiteral()), null) } break diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt index 373e35b19a9..7e98ff054cf 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt @@ -11,7 +11,25 @@ fun test(d: dynamic) { d.foo { (x: String, y: Int) -> "" } + d.foo { (x, y: Int) -> "" } + d.foo { (x: String, y: Int): Int -> "" } d.foo { String.(x: String, y: Int): Int -> length() } + + d.foo({}) + + d.foo({ x -> }) + + d.foo({ x -> } : (Int) -> Unit) + + d.foo(@label { x -> }) + + d.foo(@label ({ x, y -> })) + + d.foo((@label ({ (x, y: Int) -> }))) + + d.foo(({ x -> })) + + d.foo((({ x -> }))) }