[FIR2IR] Fix generation of val initialization after smart-cast
If neither setter nor backing field were found for an assignment call, search overridden properties for backing fields. ^KT-57105 Fixed
This commit is contained in:
committed by
Space Team
parent
2706e5502f
commit
0e721c8fc2
+8
-1
@@ -569,7 +569,14 @@ class CallAndReferenceGenerator(
|
||||
is IrPropertySymbol -> {
|
||||
val irProperty = symbol.owner
|
||||
val setter = irProperty.setter
|
||||
val backingField = irProperty.backingField
|
||||
var backingField = irProperty.backingField
|
||||
|
||||
// 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 }
|
||||
}
|
||||
|
||||
when {
|
||||
setter != null -> IrCallImpl(
|
||||
startOffset, endOffset, type, setter.symbol,
|
||||
|
||||
+6
@@ -48995,6 +48995,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/smartCasts/nullSmartCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyInitializationAfterSmartCast.kt")
|
||||
public void testPropertyInitializationAfterSmartCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/propertyInitializationAfterSmartCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resolveToMemberOfSuperclass_overrideWithDifferentType.kt")
|
||||
public void testResolveToMemberOfSuperclass_overrideWithDifferentType() throws Exception {
|
||||
|
||||
+6
@@ -48995,6 +48995,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/smartCasts/nullSmartCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyInitializationAfterSmartCast.kt")
|
||||
public void testPropertyInitializationAfterSmartCast() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/smartCasts/propertyInitializationAfterSmartCast.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("resolveToMemberOfSuperclass_overrideWithDifferentType.kt")
|
||||
public void testResolveToMemberOfSuperclass_overrideWithDifferentType() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user