[psi2ir] Properly link corresponding property symbols.

Do not rely on PatchDeclarationParents to do so.
This commit is contained in:
Mads Ager
2020-04-08 12:13:49 +02:00
committed by Alexander Udalov
parent 8bc360fa0c
commit eec3263518
4 changed files with 17 additions and 13 deletions
@@ -275,6 +275,9 @@ class ClassGenerator(
if (delegatedDescriptor.isVar) {
irProperty.setter = generateDelegatedFunction(irDelegate, delegatedDescriptor.setter!!, delegateToDescriptor.setter!!)
}
irProperty.linkCorrespondingPropertySymbol()
return irProperty
}
@@ -86,6 +86,8 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
}
}
irProperty.linkCorrespondingPropertySymbol()
return irProperty
}
@@ -76,6 +76,8 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
irProperty.setter =
FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(setter, ktParameter)
}
irProperty.linkCorrespondingPropertySymbol()
}
}
@@ -133,6 +135,8 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
irProperty.getter = generateGetterIfRequired(ktProperty, propertyDescriptor)
irProperty.setter = generateSetterIfRequired(ktProperty, propertyDescriptor)
irProperty.linkCorrespondingPropertySymbol()
}
fun generateFakeOverrideProperty(propertyDescriptor: PropertyDescriptor, ktElement: KtPureElement): IrProperty? {
@@ -158,6 +162,7 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
this.setter = propertyDescriptor.setter?.let {
FunctionGenerator(declarationGenerator).generateFakeOverrideFunction(it, ktElement)
}
this.linkCorrespondingPropertySymbol()
}
}
@@ -189,3 +194,10 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
}
}
internal fun IrProperty.linkCorrespondingPropertySymbol() {
backingField?.correspondingPropertySymbol = symbol
getter?.correspondingPropertySymbol = symbol
setter?.correspondingPropertySymbol = symbol
}
@@ -53,19 +53,6 @@ class PatchDeclarationParentsVisitor() : IrElementVisitorVoid {
}
}
override fun visitProperty(declaration: IrProperty) {
declaration.getter?.let {
it.correspondingPropertySymbol = declaration.symbol
}
declaration.setter?.let {
it.correspondingPropertySymbol = declaration.symbol
}
declaration.backingField?.let {
it.correspondingPropertySymbol = declaration.symbol
}
super.visitProperty(declaration)
}
private fun patchParent(declaration: IrDeclaration) {
declaration.parent = declarationParentsStack.peekFirst()
}