[LL FIR] fix not-resolved getter return type in on-air resolve

This commit is contained in:
Ilya Kirillov
2022-08-09 11:14:05 +02:00
parent 9f1ecdfaa1
commit 230c21f502
@@ -31,33 +31,24 @@ internal object DeclarationCopyBuilder {
} }
fun FirProperty.withBodyFrom(propertyWithBody: FirProperty): FirProperty { fun FirProperty.withBodyFrom(propertyWithBody: FirProperty): FirProperty {
val originalSetter = this@withBodyFrom.setter val newSetter = getAccessorToUse(this, propertyWithBody) { it.setter }
val replacementSetter = propertyWithBody.setter val newGetter = getAccessorToUse(this, propertyWithBody) { it.getter }
// setter has a header with `value` parameter, and we want it type to be resolved
val copySetter = if (originalSetter != null && replacementSetter != null) {
buildPropertyAccessorCopy(originalSetter) {
body = replacementSetter.body
symbol = replacementSetter.symbol
initDeclaration(originalSetter, replacementSetter)
}.apply { reassignAllReturnTargets(replacementSetter) }
} else {
replacementSetter
}
val propertyResolvePhase = minOf( val propertyResolvePhase = minOf(
this@withBodyFrom.resolvePhase, this@withBodyFrom.resolvePhase,
FirResolvePhase.DECLARATIONS, FirResolvePhase.DECLARATIONS,
copySetter?.resolvePhase ?: FirResolvePhase.BODY_RESOLVE, newGetter?.resolvePhase ?: FirResolvePhase.BODY_RESOLVE,
newSetter?.resolvePhase ?: FirResolvePhase.BODY_RESOLVE,
propertyWithBody.getter?.resolvePhase ?: FirResolvePhase.BODY_RESOLVE, propertyWithBody.getter?.resolvePhase ?: FirResolvePhase.BODY_RESOLVE,
propertyWithBody.setter?.resolvePhase ?: FirResolvePhase.BODY_RESOLVE,
) )
return buildPropertyCopy(this@withBodyFrom) { return buildPropertyCopy(this@withBodyFrom) {
symbol = propertyWithBody.symbol symbol = propertyWithBody.symbol
initializer = propertyWithBody.initializer initializer = propertyWithBody.initializer
getter = propertyWithBody.getter getter = newGetter
setter = copySetter setter = newSetter
if (propertyResolvePhase < FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE) { if (propertyResolvePhase < FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE) {
bodyResolveState = FirPropertyBodyResolveState.NOTHING_RESOLVED bodyResolveState = FirPropertyBodyResolveState.NOTHING_RESOLVED
@@ -68,6 +59,26 @@ internal object DeclarationCopyBuilder {
} }
} }
private inline fun getAccessorToUse(
originalProperty: FirProperty,
replacementProperty: FirProperty,
getAccessor: (FirProperty) -> FirPropertyAccessor?
): FirPropertyAccessor? {
val originalAccessor = getAccessor(originalProperty)
val replacementAccessor = getAccessor(replacementProperty)
// accessor has a header type, and we want it type to be resolved
return if (originalAccessor != null && replacementAccessor != null) {
buildPropertyAccessorCopy(originalAccessor) {
body = replacementAccessor.body
symbol = replacementAccessor.symbol
initDeclaration(originalAccessor, replacementAccessor)
}.apply { reassignAllReturnTargets(replacementAccessor) }
} else {
replacementAccessor
}
}
private fun FirDeclarationBuilder.initDeclaration( private fun FirDeclarationBuilder.initDeclaration(
originalDeclaration: FirDeclaration, originalDeclaration: FirDeclaration,
builtDeclaration: FirDeclaration, builtDeclaration: FirDeclaration,