IrTypes: IrProperty has no type of its own

Within the current scheme, type parameters for IrProperty become type
parameters for getter and setter (and, since only extension properties
can have type parameters, backing field's type can't depend on type
parameters; see also KT-24643). Either properties themselves can have
type parameters of their own (for the sake of representing the property
type), or properties don't have types and don't have type parameters.
This commit is contained in:
Dmitry Petrov
2018-05-28 15:23:44 +03:00
parent ad65fa8c45
commit 7497372f65
10 changed files with 17 additions and 33 deletions
@@ -171,21 +171,21 @@ class ClassGenerator(
private fun generateDelegatedProperty(
irDelegate: IrField,
delegated: PropertyDescriptor,
overridden: PropertyDescriptor
delegatedDescriptor: PropertyDescriptor,
overriddenDescriptor: PropertyDescriptor
): IrPropertyImpl {
val startOffset = irDelegate.startOffset
val endOffset = irDelegate.endOffset
val irProperty = IrPropertyImpl(
startOffset, endOffset, IrDeclarationOrigin.DELEGATED_MEMBER,
false, delegated, delegated.type.toIrType()
false, delegatedDescriptor
)
irProperty.getter = generateDelegatedFunction(irDelegate, delegated.getter!!, overridden.getter!!)
irProperty.getter = generateDelegatedFunction(irDelegate, delegatedDescriptor.getter!!, overriddenDescriptor.getter!!)
if (delegated.isVar) {
irProperty.setter = generateDelegatedFunction(irDelegate, delegated.setter!!, overridden.setter!!)
if (delegatedDescriptor.isVar) {
irProperty.setter = generateDelegatedFunction(irDelegate, delegatedDescriptor.setter!!, overriddenDescriptor.setter!!)
}
return irProperty
}
@@ -168,7 +168,6 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
IrDeclarationOrigin.FAKE_OVERRIDE,
false,
propertyDescriptor,
propertyDescriptor.type.toIrType(),
backingField,
propertyDescriptor.getter?.let { generateFakeOverrideFunction(it, ktElement) },
propertyDescriptor.setter?.let { generateFakeOverrideFunction(it, ktElement) }
@@ -58,8 +58,7 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
val irProperty = IrPropertyImpl(
ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFINED,
isDelegated = true,
descriptor = propertyDescriptor,
type = propertyDescriptor.type.toIrType()
descriptor = propertyDescriptor
).apply {
backingField = generateDelegateFieldForProperty(propertyDescriptor, kPropertyType, ktDelegate)
}
@@ -48,8 +48,7 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
return IrPropertyImpl(
ktParameter.startOffset, ktParameter.endOffset,
IrDeclarationOrigin.DEFINED, false,
propertyDescriptor,
irPropertyType
propertyDescriptor
).also { irProperty ->
irProperty.backingField =
generatePropertyBackingField(ktParameter, propertyDescriptor) {
@@ -104,8 +103,7 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
ktProperty.startOffset, ktProperty.endOffset,
IrDeclarationOrigin.DEFINED,
false,
propertyDescriptor,
propertyDescriptor.type.toIrType()
propertyDescriptor
).buildWithScope { irProperty ->
irProperty.backingField =
if (propertyDescriptor.hasBackingField())
@@ -26,7 +26,6 @@ interface IrProperty : IrDeclaration {
override val descriptor: PropertyDescriptor
val name: Name
val type: IrType
val modality: Modality
val visibility: Visibility
val isVar: Boolean
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.Visibility
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.transform
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
@@ -34,7 +33,6 @@ class IrPropertyImpl(
origin: IrDeclarationOrigin,
override val descriptor: PropertyDescriptor,
override val name: Name,
override val type: IrType,
override val visibility: Visibility,
override val modality: Modality,
override val isVar: Boolean,
@@ -50,11 +48,10 @@ class IrPropertyImpl(
endOffset: Int,
origin: IrDeclarationOrigin,
isDelegated: Boolean,
descriptor: PropertyDescriptor,
type: IrType
descriptor: PropertyDescriptor
) : this(
startOffset, endOffset, origin, descriptor,
descriptor.name, type, descriptor.visibility, descriptor.modality,
descriptor.name, descriptor.visibility, descriptor.modality,
isVar = descriptor.isVar,
isConst = descriptor.isConst,
isLateinit = descriptor.isLateInit,
@@ -66,9 +63,8 @@ class IrPropertyImpl(
startOffset: Int,
endOffset: Int,
origin: IrDeclarationOrigin,
descriptor: PropertyDescriptor,
type: IrType
) : this(startOffset, endOffset, origin, descriptor.isDelegated, descriptor, type)
descriptor: PropertyDescriptor
) : this(startOffset, endOffset, origin, descriptor.isDelegated, descriptor)
constructor(
startOffset: Int,
@@ -76,9 +72,8 @@ class IrPropertyImpl(
origin: IrDeclarationOrigin,
isDelegated: Boolean,
descriptor: PropertyDescriptor,
type: IrType,
backingField: IrField?
) : this(startOffset, endOffset, origin, isDelegated, descriptor, type) {
) : this(startOffset, endOffset, origin, isDelegated, descriptor) {
this.backingField = backingField
}
@@ -88,11 +83,10 @@ class IrPropertyImpl(
origin: IrDeclarationOrigin,
isDelegated: Boolean,
descriptor: PropertyDescriptor,
type: IrType,
backingField: IrField?,
getter: IrSimpleFunction?,
setter: IrSimpleFunction?
) : this(startOffset, endOffset, origin, isDelegated, descriptor, type, backingField) {
) : this(startOffset, endOffset, origin, isDelegated, descriptor, backingField) {
this.getter = getter
this.setter = setter
}
@@ -62,10 +62,7 @@ class DeclarationStubGenerator(
}
private fun generatePropertyStub(descriptor: PropertyDescriptor): IrProperty =
IrPropertyImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
descriptor, descriptor.type.toIrType()
).also { irProperty ->
IrPropertyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor).also { irProperty ->
val getterDescriptor = descriptor.getter
if (getterDescriptor == null) {
irProperty.backingField =
@@ -227,7 +227,6 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
mapDeclarationOrigin(declaration.origin),
declaration.isDelegated,
mapPropertyDeclaration(declaration.descriptor),
declaration.type, // TODO
declaration.backingField?.transform(),
declaration.getter?.transform(),
declaration.setter?.transform()
@@ -160,7 +160,6 @@ open class DeepCopyIrTreeWithSymbols(
mapDeclarationOrigin(declaration.origin),
declaration.isDelegated,
declaration.descriptor,
declaration.type.remapType(),
declaration.backingField?.transform(),
declaration.getter?.transform(),
declaration.setter?.transform()
@@ -101,7 +101,7 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
override fun visitProperty(declaration: IrProperty, data: Nothing?): String =
declaration.run {
"PROPERTY ${renderOriginIfNonTrivial()}" +
"name:$name type:${type.render()} visibility:$visibility modality:$modality " +
"name:$name visibility:$visibility modality:$modality " +
"flags:${renderPropertyFlags()}"
}