Drop PropertyDescriptorImpl.setType that takes KotlinType
Only use the other setType that takes an instance of ReceiverParameterDescriptor. This will make sure that call sites can use correct receiver annotations
This commit is contained in:
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertySetterDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
@@ -95,7 +96,10 @@ open class AccessorForPropertyDescriptor private constructor(
|
||||
)
|
||||
|
||||
init {
|
||||
setType(propertyType, emptyList<TypeParameterDescriptorImpl>(), dispatchReceiverParameter, receiverType)
|
||||
setType(
|
||||
propertyType, emptyList<TypeParameterDescriptorImpl>(), dispatchReceiverParameter,
|
||||
DescriptorFactory.createExtensionReceiverParameterForCallable(this, receiverType, Annotations.EMPTY)
|
||||
)
|
||||
|
||||
val getterDescriptor =
|
||||
if (isWithSyntheticGetterAccessor) Getter(this, accessorKind) else calleeDescriptor.getter as PropertyGetterDescriptorImpl?
|
||||
|
||||
+5
-1
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.incremental.record
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
@@ -337,7 +338,10 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
||||
|
||||
val propertyType = typeSubstitutor.safeSubstitute(type, Variance.INVARIANT)
|
||||
val receiverType = typeSubstitutor.safeSubstitute(ownerClass.defaultType, Variance.INVARIANT)
|
||||
descriptor.setType(propertyType, typeParameters, null, receiverType)
|
||||
descriptor.setType(
|
||||
propertyType, typeParameters, null,
|
||||
DescriptorFactory.createExtensionReceiverParameterForCallable(descriptor, receiverType, Annotations.EMPTY)
|
||||
)
|
||||
|
||||
val getter = PropertyGetterDescriptorImpl(
|
||||
descriptor,
|
||||
|
||||
@@ -1230,9 +1230,7 @@ public class DescriptorResolver {
|
||||
false
|
||||
);
|
||||
propertyWrapper.setDescriptor(propertyDescriptor);
|
||||
propertyDescriptor.setType(
|
||||
type, Collections.emptyList(), getDispatchReceiverParameterIfNeeded(classDescriptor), (ReceiverParameterDescriptor) null
|
||||
);
|
||||
propertyDescriptor.setType(type, Collections.emptyList(), getDispatchReceiverParameterIfNeeded(classDescriptor), null);
|
||||
|
||||
Annotations setterAnnotations = annotationSplitter.getAnnotationsForTarget(PROPERTY_SETTER);
|
||||
Annotations getterAnnotations = new CompositeAnnotations(CollectionsKt.listOf(
|
||||
|
||||
@@ -179,7 +179,7 @@ class LocalVariableResolver(
|
||||
type = variableTypeAndInitializerResolver.resolveType(propertyDescriptor, scope, variable, dataFlowInfo, trace, local = true)
|
||||
|
||||
val receiverParameter = (containingDeclaration as ScriptDescriptor).thisAsReceiverParameter
|
||||
propertyDescriptor.setType(type, emptyList<TypeParameterDescriptor>(), receiverParameter, null as KotlinType?)
|
||||
propertyDescriptor.setType(type, emptyList<TypeParameterDescriptor>(), receiverParameter, null)
|
||||
initializeWithDefaultGetterSetter(propertyDescriptor)
|
||||
trace.record(BindingContext.VARIABLE, variable, propertyDescriptor)
|
||||
result = propertyDescriptor
|
||||
|
||||
@@ -104,7 +104,7 @@ class DynamicCallableDescriptors(storageManager: StorageManager, builtIns: Kotli
|
||||
dynamicType,
|
||||
createTypeParameters(propertyDescriptor, call),
|
||||
createDynamicDispatchReceiverParameter(propertyDescriptor),
|
||||
null as KotlinType?
|
||||
null
|
||||
)
|
||||
|
||||
val getter = DescriptorFactory.createDefaultGetter(propertyDescriptor, Annotations.EMPTY)
|
||||
|
||||
+5
-3
@@ -7,10 +7,12 @@ package org.jetbrains.kotlin.resolve.lazy.descriptors.script
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertySetterDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyScriptDescriptor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class ScriptEnvironmentPropertyDescriptor(
|
||||
name: Name,
|
||||
@@ -32,7 +34,7 @@ class ScriptEnvironmentPropertyDescriptor(
|
||||
/* isDelegated = */ false
|
||||
) {
|
||||
init {
|
||||
setType(typeDescriptor.defaultType, emptyList<TypeParameterDescriptorImpl>(), receiver, null as KotlinType?)
|
||||
setType(typeDescriptor.defaultType, emptyList(), receiver, null)
|
||||
initialize(
|
||||
makePropertyGetterDescriptor(),
|
||||
if (!isVar) null else makePropertySetterDescriptor()
|
||||
|
||||
+2
-8
@@ -53,17 +53,11 @@ class JsDescriptorsFactory : DescriptorsFactory {
|
||||
false,
|
||||
false
|
||||
).apply {
|
||||
setType(
|
||||
outerClass.defaultType.toKotlinType(),
|
||||
emptyList(),
|
||||
innerClass.descriptor.thisAsReceiverParameter,
|
||||
null as? ReceiverParameterDescriptor
|
||||
)
|
||||
setType(outerClass.defaultType.toKotlinType(), emptyList(), innerClass.descriptor.thisAsReceiverParameter, null)
|
||||
initialize(null, null)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
override fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: IrConstructor): IrConstructorSymbol {
|
||||
val innerClass = innerClassConstructor.parent as IrClass
|
||||
assert(innerClass.isInner) { "Class is not inner: $innerClass" }
|
||||
@@ -109,7 +103,7 @@ class JsDescriptorsFactory : DescriptorsFactory {
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED, SourceElement.NO_SOURCE, /* lateInit = */ false, /* isConst = */ false,
|
||||
/* isExpect = */ false, /* isActual = */ false, /* isExternal = */ false, /* isDelegated = */ false
|
||||
).apply {
|
||||
setType(objectDescriptor.defaultType, emptyList(), null, null as ReceiverParameterDescriptor)
|
||||
setType(objectDescriptor.defaultType, emptyList(), null, null)
|
||||
initialize(null, null)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -173,8 +173,7 @@ class JsSharedVariablesManager(val builtIns: KotlinBuiltIns, val jsInterinalPack
|
||||
false
|
||||
)
|
||||
|
||||
|
||||
desc.setType(builtIns.anyType, emptyList(), closureBoxTypeDescriptor.thisAsReceiverParameter, null as ReceiverParameterDescriptor?)
|
||||
desc.setType(builtIns.anyType, emptyList(), closureBoxTypeDescriptor.thisAsReceiverParameter, null)
|
||||
desc.initialize(null, null)
|
||||
|
||||
return desc
|
||||
|
||||
+2
-1
@@ -361,7 +361,8 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
|
||||
/* outType = */ substituteTypeAndTryGetCopied(oldDescriptor.type)!!,
|
||||
/* typeParameters = */ oldDescriptor.typeParameters,
|
||||
/* dispatchReceiverParameter = */ (containingDeclaration as ClassDescriptor).thisAsReceiverParameter,
|
||||
/* receiverType = */ substituteTypeAndTryGetCopied(oldDescriptor.extensionReceiverParameter?.type))
|
||||
/* extensionReceiverParameter= */ copyReceiverParameter(oldDescriptor.extensionReceiverParameter, this)
|
||||
)
|
||||
|
||||
initialize(
|
||||
/* getter = */ oldDescriptor.getter?.let { copyPropertyGetterDescriptor(it, this) },
|
||||
|
||||
+1
-1
@@ -474,7 +474,7 @@ class CallableReferenceLowering(val context: JvmBackendContext) : FileLoweringPa
|
||||
/* outType = */ superNameProperty.type,
|
||||
/* typeParameters = */ superNameProperty.typeParameters,
|
||||
/* dispatchReceiverParameter = */ superNameProperty.dispatchReceiverParameter,
|
||||
/* receiverType = */ superNameProperty.extensionReceiverParameter?.type
|
||||
/* extensionReceiverParameter= */ superNameProperty.extensionReceiverParameter
|
||||
)
|
||||
//overriddenDescriptors += superNameProperty.getter
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import java.lang.UnsupportedOperationException
|
||||
|
||||
interface IrDelegateDescriptor : PropertyDescriptor
|
||||
|
||||
@@ -68,13 +67,7 @@ abstract class IrDelegateDescriptorBase(
|
||||
/* isDelegated = */ true
|
||||
) {
|
||||
init {
|
||||
val typeParameters: List<TypeParameterDescriptor> = emptyList()
|
||||
val extensionReceiverParameter: ReceiverParameterDescriptor? = null
|
||||
val dispatchReceiverParameter =
|
||||
if (containingDeclaration is ClassDescriptor)
|
||||
containingDeclaration.thisAsReceiverParameter
|
||||
else null
|
||||
setType(delegateType, typeParameters, dispatchReceiverParameter, extensionReceiverParameter)
|
||||
setType(delegateType, emptyList(), (containingDeclaration as? ClassDescriptor)?.thisAsReceiverParameter, null)
|
||||
}
|
||||
|
||||
final override fun setOutType(outType: KotlinType?) {
|
||||
|
||||
@@ -15,21 +15,14 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeParameterImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.toIrType
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
/**
|
||||
* Binds the arguments explicitly represented in the IR to the parameters of the accessed function.
|
||||
@@ -363,8 +356,7 @@ fun createField(
|
||||
).apply {
|
||||
initialize(null, null)
|
||||
|
||||
val receiverType: KotlinType? = null
|
||||
setType(type.toKotlinType(), emptyList(), owner.thisAsReceiverParameter, receiverType)
|
||||
setType(type.toKotlinType(), emptyList(), owner.thisAsReceiverParameter, null)
|
||||
}
|
||||
|
||||
return IrFieldImpl(startOffset, endOffset, origin, descriptor, type)
|
||||
|
||||
+7
-1
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertySetterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.load.java.typeEnhancement.TypeEnhancementKt;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
import java.util.List;
|
||||
@@ -138,11 +139,16 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja
|
||||
|
||||
enhanced.setOverriddenDescriptors(getOverriddenDescriptors());
|
||||
|
||||
ReceiverParameterDescriptor enhancedReceiver =
|
||||
enhancedReceiverType == null ? null : DescriptorFactory.createExtensionReceiverParameterForCallable(
|
||||
this, enhancedReceiverType, Annotations.Companion.getEMPTY()
|
||||
);
|
||||
|
||||
enhanced.setType(
|
||||
enhancedReturnType,
|
||||
getTypeParameters(), // TODO
|
||||
getDispatchReceiverParameter(),
|
||||
enhancedReceiverType
|
||||
enhancedReceiver
|
||||
);
|
||||
return enhanced;
|
||||
}
|
||||
|
||||
+2
-2
@@ -489,7 +489,7 @@ class LazyJavaClassMemberScope(
|
||||
propertyDescriptor.initialize(getter, null)
|
||||
|
||||
val returnType = givenType ?: computeMethodReturnType(method, c.childForMethod(propertyDescriptor, method))
|
||||
propertyDescriptor.setType(returnType, listOf(), getDispatchReceiverParameter(), null as KotlinType?)
|
||||
propertyDescriptor.setType(returnType, listOf(), getDispatchReceiverParameter(), null)
|
||||
getter.initialize(returnType)
|
||||
|
||||
return propertyDescriptor
|
||||
@@ -519,7 +519,7 @@ class LazyJavaClassMemberScope(
|
||||
/* isStaticFinal = */ false
|
||||
)
|
||||
|
||||
propertyDescriptor.setType(getterMethod.returnType!!, listOf(), getDispatchReceiverParameter(), null as KotlinType?)
|
||||
propertyDescriptor.setType(getterMethod.returnType!!, listOf(), getDispatchReceiverParameter(), null)
|
||||
|
||||
val getter = DescriptorFactory.createGetter(
|
||||
propertyDescriptor, getterMethod.annotations, /* isDefault = */false,
|
||||
|
||||
+1
-1
@@ -275,7 +275,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
|
||||
|
||||
val propertyType = getPropertyType(field)
|
||||
|
||||
propertyDescriptor.setType(propertyType, listOf(), getDispatchReceiverParameter(), null as KotlinType?)
|
||||
propertyDescriptor.setType(propertyType, listOf(), getDispatchReceiverParameter(), null)
|
||||
|
||||
if (DescriptorUtils.shouldRecordInitializerForProperty(propertyDescriptor, propertyDescriptor.type)) {
|
||||
propertyDescriptor.setCompileTimeInitializer(
|
||||
|
||||
+10
-16
@@ -22,7 +22,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.DescriptorFactory;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.utils.SmartSet;
|
||||
|
||||
@@ -106,17 +106,6 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
isExpect, isActual, isExternal, isDelegated);
|
||||
}
|
||||
|
||||
public void setType(
|
||||
@NotNull KotlinType outType,
|
||||
@ReadOnly @NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
|
||||
@Nullable KotlinType receiverType
|
||||
) {
|
||||
ReceiverParameterDescriptor extensionReceiverParameter =
|
||||
DescriptorFactory.createExtensionReceiverParameterForCallable(this, receiverType, Annotations.Companion.getEMPTY());
|
||||
setType(outType, typeParameters, dispatchReceiverParameter, extensionReceiverParameter);
|
||||
}
|
||||
|
||||
public void setType(
|
||||
@NotNull KotlinType outType,
|
||||
@ReadOnly @NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@@ -366,16 +355,21 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
substitutedDispatchReceiver = null;
|
||||
}
|
||||
|
||||
KotlinType substitutedReceiverType;
|
||||
ReceiverParameterDescriptor substitutedExtensionReceiver;
|
||||
if (extensionReceiverParameter != null) {
|
||||
substitutedReceiverType = substitutor.substitute(extensionReceiverParameter.getType(), Variance.IN_VARIANCE);
|
||||
KotlinType substitutedReceiverType = substitutor.substitute(extensionReceiverParameter.getType(), Variance.IN_VARIANCE);
|
||||
if (substitutedReceiverType == null) return null;
|
||||
substitutedExtensionReceiver = new ReceiverParameterDescriptorImpl(
|
||||
substitutedDescriptor,
|
||||
new ExtensionReceiver(substitutedDescriptor, substitutedReceiverType, extensionReceiverParameter.getValue()),
|
||||
extensionReceiverParameter.getAnnotations()
|
||||
);
|
||||
}
|
||||
else {
|
||||
substitutedReceiverType = null;
|
||||
substitutedExtensionReceiver = null;
|
||||
}
|
||||
|
||||
substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedDispatchReceiver, substitutedReceiverType);
|
||||
substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedDispatchReceiver, substitutedExtensionReceiver);
|
||||
|
||||
PropertyGetterDescriptorImpl newGetter = getter == null ? null : new PropertyGetterDescriptorImpl(
|
||||
substitutedDescriptor, getter.getAnnotations(), copyConfiguration.modality, normalizeVisibility(getter.getVisibility(), copyConfiguration.kind),
|
||||
|
||||
@@ -431,11 +431,7 @@ public class ErrorUtils {
|
||||
SourceElement.NO_SOURCE,
|
||||
false, false, false, false, false, false
|
||||
);
|
||||
descriptor.setType(ERROR_PROPERTY_TYPE,
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
null,
|
||||
(KotlinType) null
|
||||
);
|
||||
descriptor.setType(ERROR_PROPERTY_TYPE, Collections.<TypeParameterDescriptor>emptyList(), null, null);
|
||||
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
+3
-1
@@ -63,7 +63,9 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
local.typeDeserializer.type(proto.returnType(c.typeTable)),
|
||||
local.typeDeserializer.ownTypeParameters,
|
||||
getDispatchReceiverParameter(),
|
||||
proto.receiverType(c.typeTable)?.let { local.typeDeserializer.type(it, receiverAnnotations) }
|
||||
proto.receiverType(c.typeTable)?.let { local.typeDeserializer.type(it, receiverAnnotations) }?.let { receiverType ->
|
||||
DescriptorFactory.createExtensionReceiverParameterForCallable(property, receiverType, Annotations.EMPTY)
|
||||
}
|
||||
)
|
||||
|
||||
val getter = if (hasGetter) {
|
||||
|
||||
+2
-1
@@ -123,7 +123,8 @@ private fun genProperty(
|
||||
flexibleType,
|
||||
emptyList<TypeParameterDescriptor>(),
|
||||
null,
|
||||
receiverType)
|
||||
DescriptorFactory.createExtensionReceiverParameterForCallable(property, receiverType, Annotations.EMPTY)
|
||||
)
|
||||
|
||||
val getter = PropertyGetterDescriptorImpl(
|
||||
property,
|
||||
|
||||
Reference in New Issue
Block a user