[FE] Support functional literals with context receivers

This commit is contained in:
Anastasiya Shadrina
2021-08-14 00:07:06 +07:00
committed by TeamCityServer
parent e3f987459c
commit 16b976f0e0
4 changed files with 50 additions and 15 deletions
@@ -198,9 +198,11 @@ class FunctionDescriptorResolver(
}
val contextReceivers = function.contextReceivers
val contextReceiverTypes = contextReceivers.mapNotNull { it.typeReference() }.map {
typeResolver.resolveType(headerScope, it, trace, true)
}
val contextReceiverTypes =
if (function is KtFunctionLiteral) expectedFunctionType.getContextReceiversTypes()
else contextReceivers
.mapNotNull { it.typeReference() }
.map { typeResolver.resolveType(headerScope, it, trace, true) }
val valueParameterDescriptors =
createValueParameterDescriptors(function, functionDescriptor, headerScope, trace, expectedFunctionType, inferenceSession)
@@ -351,6 +353,9 @@ class FunctionDescriptorResolver(
private fun KotlinType.getReceiverType(): KotlinType? =
if (functionTypeExpected()) this.getReceiverTypeFromFunctionType() else null
private fun KotlinType.getContextReceiversTypes(): List<KotlinType> =
if (functionTypeExpected()) this.getContextReceiverTypesFromFunctionType() else emptyList()
private fun KotlinType.getValueParameters(owner: FunctionDescriptor): List<ValueParameterDescriptor>? =
if (functionTypeExpected()) {
createValueParametersForInvokeInFunctionType(owner, this.getValueParameterTypesFromFunctionType())