[NI] Support callable references to suspend functions

#KT-30658 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-03-28 11:50:37 +03:00
parent 017f9aea35
commit 1ac25259e8
6 changed files with 52 additions and 5 deletions
@@ -315,7 +315,7 @@ class CallableReferencesCandidateFactory(
return callComponents.reflectionTypes.getKFunctionType(
Annotations.EMPTY, null, argumentsAndReceivers, null,
returnType, descriptor.builtIns, isSuspend = false
returnType, descriptor.builtIns, descriptor.isSuspend
) to defaults
}
else -> error("Unsupported descriptor type: $descriptor")
@@ -347,17 +347,22 @@ fun extractInputOutputTypesFromCallableReferenceExpectedType(expectedType: Unwra
if (expectedType == null) return null
return when {
expectedType.isFunctionType ->
expectedType.isFunctionType || expectedType.isSuspendFunctionType ->
extractInputOutputTypesFromFunctionType(expectedType)
ReflectionTypes.isBaseTypeForNumberedReferenceTypes(expectedType) ->
InputOutputTypes(emptyList(), expectedType.arguments.single().type.unwrap())
ReflectionTypes.isNumberedKFunctionOrKSuspendFunction(expectedType) -> {
ReflectionTypes.isNumberedKFunction(expectedType) -> {
val functionFromSupertype = expectedType.immediateSupertypes().first { it.isFunctionType }.unwrap()
extractInputOutputTypesFromFunctionType(functionFromSupertype)
}
ReflectionTypes.isNumberedKSuspendFunction(expectedType) -> {
val kSuspendFunctionType = expectedType.immediateSupertypes().first { it.isSuspendFunctionType }.unwrap()
extractInputOutputTypesFromFunctionType(kSuspendFunctionType)
}
ReflectionTypes.isNumberedKPropertyOrKMutablePropertyType(expectedType) -> {
val functionFromSupertype = expectedType.supertypes().first { it.isFunctionType }.unwrap()
extractInputOutputTypesFromFunctionType(functionFromSupertype)