Frontend: allow omit types in lambda parameters of dynamic call when lambda declareted inside parentheses.

This commit is contained in:
Zalim Bashorov
2014-12-12 17:44:37 +03:00
parent 59c4f55988
commit a6597e8926
2 changed files with 27 additions and 5 deletions
@@ -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
@@ -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 -> <!TYPE_MISMATCH!>""<!> }
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 -> })))
}