[FIR2IR] Fix generation of val initialization after smart-cast, again

#KT-57284
This commit is contained in:
Kirill Rakhman
2023-03-15 10:49:57 +01:00
committed by Space Team
parent f1c673c166
commit 7a6a3a0b1d
2 changed files with 23 additions and 3 deletions
@@ -572,7 +572,7 @@ class CallAndReferenceGenerator(
// If we found neither a setter nor a backing field, check if we have an override (possibly fake) of a val with
// backing field. This can happen in a class initializer where `this` was smart-casted. See KT-57105.
if (setter == null && backingField == null) {
backingField = irProperty.overriddenSymbols.firstNotNullOfOrNull { it.owner.backingField }
backingField = irProperty.overriddenBackingFieldOrNull()
}
when {
@@ -624,6 +624,13 @@ class CallAndReferenceGenerator(
}
}
private fun IrProperty.overriddenBackingFieldOrNull(): IrField? {
return overriddenSymbols.firstNotNullOfOrNull {
val owner = it.owner
owner.backingField ?: owner.overriddenBackingFieldOrNull()
}
}
fun convertToIrConstructorCall(annotation: FirAnnotation): IrExpression {
val coneType = annotation.annotationTypeRef.coneTypeSafe<ConeLookupTagBasedType>()
?.fullyExpandedType(session) as? ConeLookupTagBasedType