Frontend: allow omit types in lambda parameters of dynamic call when lambda declareted inside parentheses.
This commit is contained in:
@@ -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.types.lang.KotlinBuiltIns
|
||||||
import org.jetbrains.jet.lang.psi.ValueArgument
|
import org.jetbrains.jet.lang.psi.ValueArgument
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||||
|
|
||||||
object DynamicCallableDescriptors {
|
object DynamicCallableDescriptors {
|
||||||
|
|
||||||
@@ -185,8 +187,8 @@ object DynamicCallableDescriptors {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFunctionType(arg: JetFunctionLiteralArgument): JetType {
|
fun getFunctionType(funLiteralExpr: JetFunctionLiteralExpression): JetType {
|
||||||
val funLiteral = arg.getFunctionLiteral().getFunctionLiteral()
|
val funLiteral = funLiteralExpr.getFunctionLiteral()
|
||||||
|
|
||||||
val receiverType = funLiteral.getReceiverTypeReference()?.let { DynamicType }
|
val receiverType = funLiteral.getReceiverTypeReference()?.let { DynamicType }
|
||||||
val parameterTypes = funLiteral.getValueParameters().map { DynamicType }
|
val parameterTypes = funLiteral.getValueParameters().map { DynamicType }
|
||||||
@@ -199,9 +201,11 @@ object DynamicCallableDescriptors {
|
|||||||
val varargElementType: JetType?
|
val varargElementType: JetType?
|
||||||
var hasSpreadOperator = false
|
var hasSpreadOperator = false
|
||||||
|
|
||||||
|
val argExpression = JetPsiUtil.deparenthesize(arg.getArgumentExpression(), false)
|
||||||
|
|
||||||
when {
|
when {
|
||||||
arg is JetFunctionLiteralArgument -> {
|
argExpression is JetFunctionLiteralExpression -> {
|
||||||
outType = getFunctionType(arg)
|
outType = getFunctionType(argExpression)
|
||||||
varargElementType = null
|
varargElementType = null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +225,7 @@ object DynamicCallableDescriptors {
|
|||||||
|
|
||||||
if (hasSpreadOperator) {
|
if (hasSpreadOperator) {
|
||||||
for (funLiteralArg in call.getFunctionLiteralArguments()) {
|
for (funLiteralArg in call.getFunctionLiteralArguments()) {
|
||||||
addParameter(funLiteralArg, getFunctionType(funLiteralArg), null)
|
addParameter(funLiteralArg, getFunctionType(funLiteralArg.getFunctionLiteral()), null)
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|||||||
+18
@@ -11,7 +11,25 @@ fun test(d: dynamic) {
|
|||||||
|
|
||||||
d.foo { (x: String, y: Int) -> "" }
|
d.foo { (x: String, y: Int) -> "" }
|
||||||
|
|
||||||
|
d.foo { (x, y: Int) -> "" }
|
||||||
|
|
||||||
d.foo { (x: String, y: Int): Int -> <!TYPE_MISMATCH!>""<!> }
|
d.foo { (x: String, y: Int): Int -> <!TYPE_MISMATCH!>""<!> }
|
||||||
|
|
||||||
d.foo { String.(x: String, y: Int): Int -> length() }
|
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 -> })))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user