[NI] Added isSuspend for lambdas.
This commit is contained in:
committed by
Mikhail Zarechenskiy
parent
29e2a26ad6
commit
acc6e48172
+2
-1
@@ -59,6 +59,7 @@ class KotlinResolutionCallbacksImpl(
|
|||||||
override fun analyzeAndGetLambdaResultArguments(
|
override fun analyzeAndGetLambdaResultArguments(
|
||||||
topLevelCall: KotlinCall,
|
topLevelCall: KotlinCall,
|
||||||
lambdaArgument: LambdaKotlinCallArgument,
|
lambdaArgument: LambdaKotlinCallArgument,
|
||||||
|
isSuspend: Boolean,
|
||||||
receiverType: UnwrappedType?,
|
receiverType: UnwrappedType?,
|
||||||
parameters: List<UnwrappedType>,
|
parameters: List<UnwrappedType>,
|
||||||
expectedReturnType: UnwrappedType?
|
expectedReturnType: UnwrappedType?
|
||||||
@@ -71,7 +72,7 @@ class KotlinResolutionCallbacksImpl(
|
|||||||
|
|
||||||
val builtIns = outerCallContext.scope.ownerDescriptor.builtIns
|
val builtIns = outerCallContext.scope.ownerDescriptor.builtIns
|
||||||
val expectedType = createFunctionType(builtIns, Annotations.EMPTY, receiverType, parameters, null,
|
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
|
val approximatesExpectedType = typeApproximator.approximateToSubType(expectedType, TypeApproximatorConfiguration.LocalDeclaration) ?: expectedType
|
||||||
|
|
||||||
|
|||||||
+8
-10
@@ -16,10 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.components
|
package org.jetbrains.kotlin.resolve.calls.components
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
import org.jetbrains.kotlin.builtins.*
|
||||||
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
|
|
||||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
|
||||||
import org.jetbrains.kotlin.builtins.isFunctionType
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
@@ -92,7 +89,7 @@ internal object CheckArguments : ResolutionPart {
|
|||||||
): List<UnwrappedType> {
|
): List<UnwrappedType> {
|
||||||
argument.parametersTypes?.map { it ?: createFreshType() } ?.let { return it }
|
argument.parametersTypes?.map { it ?: createFreshType() } ?.let { return it }
|
||||||
|
|
||||||
if (expectedType.isFunctionType) {
|
if (expectedType.isBuiltinFunctionalType) {
|
||||||
return expectedType.getValueParameterTypesFromFunctionType().map { createFreshType() }
|
return expectedType.getValueParameterTypesFromFunctionType().map { createFreshType() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +104,7 @@ internal object CheckArguments : ResolutionPart {
|
|||||||
) : UnwrappedType? {
|
) : UnwrappedType? {
|
||||||
if (argument is FunctionExpression) return argument.receiverType
|
if (argument is FunctionExpression) return argument.receiverType
|
||||||
|
|
||||||
if (expectedType.isExtensionFunctionType) return createFreshType()
|
if (expectedType.isBuiltinExtensionFunctionalType) return createFreshType()
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -128,7 +125,7 @@ internal object CheckArguments : ResolutionPart {
|
|||||||
expectedType: UnwrappedType
|
expectedType: UnwrappedType
|
||||||
): KotlinCallDiagnostic? {
|
): KotlinCallDiagnostic? {
|
||||||
// initial checks
|
// initial checks
|
||||||
if (expectedType.isFunctionType) {
|
if (expectedType.isBuiltinFunctionalType) {
|
||||||
val expectedParameterCount = expectedType.getValueParameterTypesFromFunctionType().size
|
val expectedParameterCount = expectedType.getValueParameterTypesFromFunctionType().size
|
||||||
|
|
||||||
argument.parametersTypes?.size?.let {
|
argument.parametersTypes?.size?.let {
|
||||||
@@ -136,8 +133,8 @@ internal object CheckArguments : ResolutionPart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (argument is FunctionExpression) {
|
if (argument is FunctionExpression) {
|
||||||
if (argument.receiverType != null && !expectedType.isExtensionFunctionType) return UnexpectedReceiver(argument)
|
if (argument.receiverType != null && !expectedType.isBuiltinExtensionFunctionalType) return UnexpectedReceiver(argument)
|
||||||
if (argument.receiverType == null && expectedType.isExtensionFunctionType) return MissingReceiver(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
|
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)
|
freshVariables.forEach(csBuilder::registerVariable)
|
||||||
csBuilder.addSubtypeConstraint(resolvedArgument.type, expectedType, ArgumentConstraintPosition(argument))
|
csBuilder.addSubtypeConstraint(resolvedArgument.type, expectedType, ArgumentConstraintPosition(argument))
|
||||||
|
|||||||
+1
@@ -28,6 +28,7 @@ interface KotlinResolutionCallbacks {
|
|||||||
fun analyzeAndGetLambdaResultArguments(
|
fun analyzeAndGetLambdaResultArguments(
|
||||||
topLevelCall: KotlinCall,
|
topLevelCall: KotlinCall,
|
||||||
lambdaArgument: LambdaKotlinCallArgument,
|
lambdaArgument: LambdaKotlinCallArgument,
|
||||||
|
isSuspend: Boolean,
|
||||||
receiverType: UnwrappedType?,
|
receiverType: UnwrappedType?,
|
||||||
parameters: List<UnwrappedType>,
|
parameters: List<UnwrappedType>,
|
||||||
expectedReturnType: UnwrappedType? // null means, that return type is not proper i.e. it depends on some type variables
|
expectedReturnType: UnwrappedType? // null means, that return type is not proper i.e. it depends on some type variables
|
||||||
|
|||||||
+2
-1
@@ -67,6 +67,7 @@ class KotlinCallCompleter(
|
|||||||
fun transformWhenAmbiguity(candidate: KotlinResolutionCandidate, resolutionCallbacks: KotlinResolutionCallbacks): ResolvedKotlinCall =
|
fun transformWhenAmbiguity(candidate: KotlinResolutionCandidate, resolutionCallbacks: KotlinResolutionCallbacks): ResolvedKotlinCall =
|
||||||
toCompletedBaseResolvedCall(candidate.lastCall.constraintSystem.asCallCompleterContext(), candidate, resolutionCallbacks)
|
toCompletedBaseResolvedCall(candidate.lastCall.constraintSystem.asCallCompleterContext(), candidate, resolutionCallbacks)
|
||||||
|
|
||||||
|
// todo investigate variable+function calls
|
||||||
fun completeCallIfNecessary(
|
fun completeCallIfNecessary(
|
||||||
candidate: KotlinResolutionCandidate,
|
candidate: KotlinResolutionCandidate,
|
||||||
expectedType: UnwrappedType?,
|
expectedType: UnwrappedType?,
|
||||||
@@ -259,7 +260,7 @@ class KotlinCallCompleter(
|
|||||||
val parameters = lambda.parameters.map(::substitute)
|
val parameters = lambda.parameters.map(::substitute)
|
||||||
val expectedType = lambda.returnType.takeIf { c.canBeProper(it) }?.let(::substitute)
|
val expectedType = lambda.returnType.takeIf { c.canBeProper(it) }?.let(::substitute)
|
||||||
lambda.analyzed = true
|
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) {
|
for (innerCall in lambda.resultArguments) {
|
||||||
// todo strange code -- why top-level kotlinCall? may be it isn't right outer call
|
// todo strange code -- why top-level kotlinCall? may be it isn't right outer call
|
||||||
|
|||||||
+2
-1
@@ -41,11 +41,12 @@ class ResolvedLambdaArgument(
|
|||||||
override val outerCall: KotlinCall,
|
override val outerCall: KotlinCall,
|
||||||
override val argument: LambdaKotlinCallArgument,
|
override val argument: LambdaKotlinCallArgument,
|
||||||
override val myTypeVariables: Collection<LambdaTypeVariable>,
|
override val myTypeVariables: Collection<LambdaTypeVariable>,
|
||||||
|
val isSuspend: Boolean,
|
||||||
val receiver: UnwrappedType?,
|
val receiver: UnwrappedType?,
|
||||||
val parameters: List<UnwrappedType>,
|
val parameters: List<UnwrappedType>,
|
||||||
val returnType: UnwrappedType
|
val returnType: UnwrappedType
|
||||||
) : ArgumentWithPostponeResolution() {
|
) : 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<UnwrappedType> get() = receiver?.let { parameters + it } ?: parameters
|
override val inputType: Collection<UnwrappedType> get() = receiver?.let { parameters + it } ?: parameters
|
||||||
override val outputType: UnwrappedType get() = returnType
|
override val outputType: UnwrappedType get() = returnType
|
||||||
|
|||||||
Reference in New Issue
Block a user