Frontend: allow omit types in lambda parameters of dynamic calls.

This commit is contained in:
Zalim Bashorov
2014-12-11 19:51:03 +03:00
parent 4dff9cf5fc
commit 4ac3cbc384
2 changed files with 26 additions and 4 deletions
@@ -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<ValueParameterDescriptor> =
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
@@ -3,11 +3,15 @@ fun test(d: dynamic) {
d.foo { <!UNRESOLVED_REFERENCE!>it<!> }
d.foo { <!CANNOT_INFER_PARAMETER_TYPE!>x<!> -> }
d.foo { x -> }
d.foo { (x: Int) -> "" }
d.foo { <!CANNOT_INFER_PARAMETER_TYPE!>x<!>, <!CANNOT_INFER_PARAMETER_TYPE!>y<!> -> "" }
d.foo { x, y -> "" }
d.foo { (x: String, y: Int) -> "" }
d.foo { (x: String, y: Int): Int -> <!TYPE_MISMATCH!>""<!> }
d.foo { String.(x: String, y: Int): Int -> length() }
}