[PSI2IR] Generate safe calls correctly

This commit is contained in:
Anastasiya Shadrina
2021-11-18 00:53:53 +07:00
committed by TeamCityServer
parent 229a009828
commit a760865767
6 changed files with 68 additions and 3 deletions
@@ -23,6 +23,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.scopes.receivers.ContextReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.utils.SmartSet;
@@ -444,7 +445,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
List<ReceiverParameterDescriptor> substitutedContextReceivers = new ArrayList<ReceiverParameterDescriptor>();
for (ReceiverParameterDescriptor contextReceiverParameter: contextReceiverParameters) {
ReceiverParameterDescriptor substitutedContextReceiver = substituteParameterDescriptor(substitutor, substitutedDescriptor,
ReceiverParameterDescriptor substitutedContextReceiver = substituteContextParameterDescriptor(substitutor, substitutedDescriptor,
contextReceiverParameter);
if (substitutedContextReceiver != null) {
substitutedContextReceivers.add(substitutedContextReceiver);
@@ -541,6 +542,20 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
);
}
private static ReceiverParameterDescriptor substituteContextParameterDescriptor(
TypeSubstitutor substitutor,
PropertyDescriptor substitutedPropertyDescriptor,
ReceiverParameterDescriptor receiverParameterDescriptor
) {
KotlinType substitutedType = substitutor.substitute(receiverParameterDescriptor.getType(), Variance.IN_VARIANCE);
if (substitutedType == null) return null;
return new ReceiverParameterDescriptorImpl(
substitutedPropertyDescriptor,
new ContextReceiver(substitutedPropertyDescriptor, substitutedType, receiverParameterDescriptor.getValue()),
receiverParameterDescriptor.getAnnotations()
);
}
private static FunctionDescriptor getSubstitutedInitialSignatureDescriptor(
@NotNull TypeSubstitutor substitutor,
@NotNull PropertyAccessorDescriptor accessorDescriptor