[FE] Minor: refactor substituteFunctionLiteralDescriptor()

This commit is contained in:
Anastasiya Shadrina
2021-11-03 17:19:29 +07:00
committed by TeamCityServer
parent c194f12cb4
commit 7494c0896b
@@ -283,27 +283,23 @@ class ResolvedAtomCompleter(
descriptor.setReturnType(it.approximatedType) descriptor.setReturnType(it.approximatedType)
} }
fun ReceiverParameterDescriptor.setOutTypeIfNecessary(processedType: FunctionLiteralTypes.ProcessedType) {
if (this is ReceiverParameterDescriptorImpl && type.shouldBeUpdated()) {
setOutType(processedType.approximatedType)
}
}
val extensionReceiverFromDescriptor = descriptor.extensionReceiverParameter val extensionReceiverFromDescriptor = descriptor.extensionReceiverParameter
val substitutedReceiverType = extensionReceiverType?.substituteAndApproximate(substitutor)?.also { val substitutedReceiverType = extensionReceiverType?.substituteAndApproximate(substitutor)?.also {
if (extensionReceiverFromDescriptor is ReceiverParameterDescriptorImpl && extensionReceiverFromDescriptor.type.shouldBeUpdated()) { extensionReceiverFromDescriptor?.setOutTypeIfNecessary(it)
extensionReceiverFromDescriptor.setOutType(it.approximatedType)
}
} }
val substitutedContextReceiversTypes = descriptor.contextReceiverParameters.mapIndexedNotNull { i, contextReceiver -> val substitutedContextReceiversTypes = descriptor.contextReceiverParameters.mapIndexedNotNull { i, contextReceiver ->
contextReceiversTypes.getOrNull(i)?.substituteAndApproximate(substitutor)?.also { contextReceiversTypes.getOrNull(i)?.substituteAndApproximate(substitutor)?.also { contextReceiver.setOutTypeIfNecessary(it) }
if (contextReceiver is ReceiverParameterDescriptorImpl && contextReceiver.type.shouldBeUpdated()) {
contextReceiver.setOutType(it.approximatedType)
}
}
} }
val dispatchReceiverFromDescriptor = descriptor.dispatchReceiverParameter val dispatchReceiverFromDescriptor = descriptor.dispatchReceiverParameter
dispatchReceiverType?.substituteAndApproximate(substitutor)?.also { dispatchReceiverType?.substituteAndApproximate(substitutor)?.also { dispatchReceiverFromDescriptor?.setOutTypeIfNecessary(it) }
if (dispatchReceiverFromDescriptor is ReceiverParameterDescriptorImpl && dispatchReceiverFromDescriptor.type.shouldBeUpdated()) {
dispatchReceiverFromDescriptor.setOutType(it.approximatedType)
}
}
val substitutedValueParameterTypes = descriptor.valueParameters.mapIndexedNotNull { i, valueParameter -> val substitutedValueParameterTypes = descriptor.valueParameters.mapIndexedNotNull { i, valueParameter ->
valueParameterTypes.getOrNull(i)?.substituteAndApproximate(substitutor)?.also { valueParameterTypes.getOrNull(i)?.substituteAndApproximate(substitutor)?.also {
@@ -313,7 +309,12 @@ class ResolvedAtomCompleter(
} }
} }
return FunctionLiteralTypes(substitutedReturnType, substitutedValueParameterTypes, substitutedReceiverType, substitutedContextReceiversTypes) return FunctionLiteralTypes(
substitutedReturnType,
substitutedValueParameterTypes,
substitutedReceiverType,
substitutedContextReceiversTypes
)
} }
private fun completeLambda(resolvedAtom: ResolvedLambdaAtom) { private fun completeLambda(resolvedAtom: ResolvedLambdaAtom) {