Support suspend conversion in callable reference adaptation

#KT-15917 In Progress
This commit is contained in:
Mikhail Zarechenskiy
2020-04-22 04:51:07 +03:00
parent 537a59d6ca
commit ac642cf175
13 changed files with 221 additions and 3 deletions
@@ -75,9 +75,14 @@ class CallableReferenceAdaptation(
val argumentTypes: Array<KotlinType>,
val coercionStrategy: CoercionStrategy,
val defaults: Int,
val mappedArguments: Map<ValueParameterDescriptor, ResolvedCallArgument>
val mappedArguments: Map<ValueParameterDescriptor, ResolvedCallArgument>,
val suspendConversionStrategy: SuspendConversionStrategy
)
enum class SuspendConversionStrategy {
SUSPEND_CONVERSION, NO_CONVERSION
}
/**
* cases: class A {}, class B { companion object }, object C, enum class D { E }
* A::foo <-> Type
@@ -332,10 +337,21 @@ class CallableReferencesCandidateFactory(
else
mappedArguments
val suspendConversionStrategy =
if (
callComponents.languageVersionSettings.supportsFeature(LanguageFeature.SuspendConversion) &&
!descriptor.isSuspend && expectedType?.isSuspendFunctionType == true
) {
SuspendConversionStrategy.SUSPEND_CONVERSION
} else {
SuspendConversionStrategy.NO_CONVERSION
}
return CallableReferenceAdaptation(
@Suppress("UNCHECKED_CAST") (mappedArgumentTypes as Array<KotlinType>),
coercion, defaults,
adaptedArguments
adaptedArguments,
suspendConversionStrategy
)
}
@@ -428,9 +444,12 @@ class CallableReferencesCandidateFactory(
descriptorReturnType
}
val suspendConversionStrategy = callableReferenceAdaptation?.suspendConversionStrategy
val isSuspend = descriptor.isSuspend || suspendConversionStrategy == SuspendConversionStrategy.SUSPEND_CONVERSION
return callComponents.reflectionTypes.getKFunctionType(
Annotations.EMPTY, null, argumentsAndReceivers, null,
returnType, descriptor.builtIns, descriptor.isSuspend
returnType, descriptor.builtIns, isSuspend
) to callableReferenceAdaptation
}
else -> return ErrorUtils.createErrorType("Unsupported descriptor type: $descriptor") to null