Take ReceiverParameterDescriptor in FunctionDescriptorImpl.initialize

Instead of just KotlinType. This will allow to pass annotations on the
receiver at call sites
This commit is contained in:
Alexander Udalov
2018-08-08 16:35:21 +02:00
parent 6fb39785ff
commit 34c033bcaf
39 changed files with 200 additions and 107 deletions
@@ -930,8 +930,15 @@ public class DescriptorResolver {
}
}
ReceiverParameterDescriptor receiverDescriptor =
DescriptorFactory.createExtensionReceiverParameterForCallable(propertyDescriptor, receiverType);
ReceiverParameterDescriptor receiverDescriptor;
if (receiverType != null) {
receiverDescriptor = DescriptorFactory.createExtensionReceiverParameterForCallable(
propertyDescriptor, receiverType, Annotations.Companion.getEMPTY()
);
}
else {
receiverDescriptor = null;
}
LexicalScope scopeForInitializer = ScopeUtils.makeScopeForPropertyInitializer(scopeForInitializerResolutionWithTypeParameters, propertyDescriptor);
KotlinType propertyType = propertyInfo.getVariableType();
@@ -210,7 +210,9 @@ class FunctionDescriptorResolver(
}
functionDescriptor.initialize(
receiverType,
receiverType?.let {
DescriptorFactory.createExtensionReceiverParameterForCallable(functionDescriptor, it, Annotations.EMPTY)
},
getDispatchReceiverParameterIfNeeded(container),
typeParameterDescriptors,
valueParameterDescriptors,
@@ -138,7 +138,7 @@ class DynamicCallableDescriptors(storageManager: StorageManager, builtIns: Kotli
}
private fun createDynamicDispatchReceiverParameter(owner: CallableDescriptor): ReceiverParameterDescriptorImpl {
return ReceiverParameterDescriptorImpl(owner, TransientReceiver(dynamicType))
return ReceiverParameterDescriptorImpl(owner, TransientReceiver(dynamicType), Annotations.EMPTY)
}
private fun createTypeParameters(owner: DeclarationDescriptor, call: Call): List<TypeParameterDescriptor> =
@@ -159,19 +159,19 @@ class ResolvedAtomCompleter(
trace.recordType(ktArgumentExpression, substitutedFunctionalType)
// Mainly this is needed for builder-like inference, when we have type `SomeType<K, V>.() -> Unit` and now we want to update those K, V
val extensionReceiverParameter = functionDescriptor.extensionReceiverParameter
if (extensionReceiverParameter != null) {
require(extensionReceiverParameter is ReceiverParameterDescriptorImpl) {
"Extension receiver for anonymous function ($extensionReceiverParameter) should be ReceiverParameterDescriptorImpl"
val receiver = functionDescriptor.extensionReceiverParameter
if (receiver != null) {
require(receiver is ReceiverParameterDescriptorImpl) {
"Extension receiver for anonymous function ($receiver) should be ReceiverParameterDescriptorImpl"
}
val valueType = extensionReceiverParameter.value.type.unwrap()
val valueType = receiver.value.type.unwrap()
val newValueType = resultSubstitutor.substituteKeepAnnotations(valueType)
val newReceiverValue = extensionReceiverParameter.value.replaceType(newValueType)
val newReceiverValue = receiver.value.replaceType(newValueType)
functionDescriptor.setExtensionReceiverParameter(
ReceiverParameterDescriptorImpl(extensionReceiverParameter.containingDeclaration, newReceiverValue)
ReceiverParameterDescriptorImpl(receiver.containingDeclaration, newReceiverValue, receiver.annotations)
)
}
}