diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index f8f776e90ab..d4c44bc1282 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -59,6 +59,7 @@ class KotlinResolutionCallbacksImpl( override fun analyzeAndGetLambdaResultArguments( topLevelCall: KotlinCall, lambdaArgument: LambdaKotlinCallArgument, + isSuspend: Boolean, receiverType: UnwrappedType?, parameters: List, expectedReturnType: UnwrappedType? @@ -71,7 +72,7 @@ class KotlinResolutionCallbacksImpl( val builtIns = outerCallContext.scope.ownerDescriptor.builtIns val expectedType = createFunctionType(builtIns, Annotations.EMPTY, receiverType, parameters, null, - expectedReturnType ?: TypeUtils.NO_EXPECTED_TYPE) + expectedReturnType ?: TypeUtils.NO_EXPECTED_TYPE, isSuspend) val approximatesExpectedType = typeApproximator.approximateToSubType(expectedType, TypeApproximatorConfiguration.LocalDeclaration) ?: expectedType diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CheckArgumentsResolutionPart.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CheckArgumentsResolutionPart.kt index abba36e84fb..4f4956ad678 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CheckArgumentsResolutionPart.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CheckArgumentsResolutionPart.kt @@ -16,10 +16,7 @@ package org.jetbrains.kotlin.resolve.calls.components -import org.jetbrains.kotlin.builtins.ReflectionTypes -import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType -import org.jetbrains.kotlin.builtins.isExtensionFunctionType -import org.jetbrains.kotlin.builtins.isFunctionType +import org.jetbrains.kotlin.builtins.* import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor @@ -92,7 +89,7 @@ internal object CheckArguments : ResolutionPart { ): List { argument.parametersTypes?.map { it ?: createFreshType() } ?.let { return it } - if (expectedType.isFunctionType) { + if (expectedType.isBuiltinFunctionalType) { return expectedType.getValueParameterTypesFromFunctionType().map { createFreshType() } } @@ -107,7 +104,7 @@ internal object CheckArguments : ResolutionPart { ) : UnwrappedType? { if (argument is FunctionExpression) return argument.receiverType - if (expectedType.isExtensionFunctionType) return createFreshType() + if (expectedType.isBuiltinExtensionFunctionalType) return createFreshType() return null } @@ -128,7 +125,7 @@ internal object CheckArguments : ResolutionPart { expectedType: UnwrappedType ): KotlinCallDiagnostic? { // initial checks - if (expectedType.isFunctionType) { + if (expectedType.isBuiltinFunctionalType) { val expectedParameterCount = expectedType.getValueParameterTypesFromFunctionType().size argument.parametersTypes?.size?.let { @@ -136,8 +133,8 @@ internal object CheckArguments : ResolutionPart { } if (argument is FunctionExpression) { - if (argument.receiverType != null && !expectedType.isExtensionFunctionType) return UnexpectedReceiver(argument) - if (argument.receiverType == null && expectedType.isExtensionFunctionType) return MissingReceiver(argument) + if (argument.receiverType != null && !expectedType.isBuiltinExtensionFunctionalType) return UnexpectedReceiver(argument) + if (argument.receiverType == null && expectedType.isBuiltinExtensionFunctionalType) return MissingReceiver(argument) } } @@ -155,7 +152,8 @@ internal object CheckArguments : ResolutionPart { LambdaTypeVariable(argument, LambdaTypeVariable.Kind.RETURN_TYPE, builtIns).apply { freshVariables.add(this) }.defaultType } - val resolvedArgument = ResolvedLambdaArgument(kotlinCall, argument, freshVariables, receiver, parameters, returnType) + val isSuspend = expectedType.isSuspendFunctionType + val resolvedArgument = ResolvedLambdaArgument(kotlinCall, argument, freshVariables, isSuspend, receiver, parameters, returnType) freshVariables.forEach(csBuilder::registerVariable) csBuilder.addSubtypeConstraint(resolvedArgument.type, expectedType, ArgumentConstraintPosition(argument)) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt index df8dab589e3..eae0571aa17 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt @@ -28,6 +28,7 @@ interface KotlinResolutionCallbacks { fun analyzeAndGetLambdaResultArguments( topLevelCall: KotlinCall, lambdaArgument: LambdaKotlinCallArgument, + isSuspend: Boolean, receiverType: UnwrappedType?, parameters: List, expectedReturnType: UnwrappedType? // null means, that return type is not proper i.e. it depends on some type variables diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index 4daca9ac863..9f805c7ddff 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -67,6 +67,7 @@ class KotlinCallCompleter( fun transformWhenAmbiguity(candidate: KotlinResolutionCandidate, resolutionCallbacks: KotlinResolutionCallbacks): ResolvedKotlinCall = toCompletedBaseResolvedCall(candidate.lastCall.constraintSystem.asCallCompleterContext(), candidate, resolutionCallbacks) + // todo investigate variable+function calls fun completeCallIfNecessary( candidate: KotlinResolutionCandidate, expectedType: UnwrappedType?, @@ -259,7 +260,7 @@ class KotlinCallCompleter( val parameters = lambda.parameters.map(::substitute) val expectedType = lambda.returnType.takeIf { c.canBeProper(it) }?.let(::substitute) lambda.analyzed = true - lambda.resultArguments = resolutionCallbacks.analyzeAndGetLambdaResultArguments(topLevelCall, lambda.argument, receiver, parameters, expectedType) + lambda.resultArguments = resolutionCallbacks.analyzeAndGetLambdaResultArguments(topLevelCall, lambda.argument, lambda.isSuspend, receiver, parameters, expectedType) for (innerCall in lambda.resultArguments) { // todo strange code -- why top-level kotlinCall? may be it isn't right outer call diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallElements.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallElements.kt index 33b26512df9..a048dbfe801 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallElements.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolvedCallElements.kt @@ -41,11 +41,12 @@ class ResolvedLambdaArgument( override val outerCall: KotlinCall, override val argument: LambdaKotlinCallArgument, override val myTypeVariables: Collection, + val isSuspend: Boolean, val receiver: UnwrappedType?, val parameters: List, val returnType: UnwrappedType ) : ArgumentWithPostponeResolution() { - val type: SimpleType = createFunctionType(returnType.builtIns, Annotations.EMPTY, receiver, parameters, null, returnType) // todo support annotations + val type: SimpleType = createFunctionType(returnType.builtIns, Annotations.EMPTY, receiver, parameters, null, returnType, isSuspend) // todo support annotations override val inputType: Collection get() = receiver?.let { parameters + it } ?: parameters override val outputType: UnwrappedType get() = returnType