[FIR] Calculate lazy initializers in properties with backing fields
More tests should be added in the future
This commit is contained in:
+7
-1
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.lazy.resolve
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.getExplicitBackingField
|
||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirWrappedDelegateExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirLazyBlock
|
||||
@@ -92,6 +92,11 @@ internal object FirLazyBodiesCalculator {
|
||||
firProperty.replaceInitializer(newProperty.initializer)
|
||||
}
|
||||
|
||||
firProperty.getExplicitBackingField()?.takeIf { it.initializer is FirLazyExpression }?.let { backingField ->
|
||||
val newInitializer = newProperty.getExplicitBackingField()?.initializer
|
||||
backingField.replaceInitializer(newInitializer)
|
||||
}
|
||||
|
||||
val delegate = firProperty.delegate as? FirWrappedDelegateExpression
|
||||
val delegateExpression = delegate?.expression
|
||||
if (delegateExpression is FirLazyExpression) {
|
||||
@@ -114,6 +119,7 @@ internal object FirLazyBodiesCalculator {
|
||||
|| firProperty.setter?.body is FirLazyBlock
|
||||
|| firProperty.initializer is FirLazyExpression
|
||||
|| (firProperty.delegate as? FirWrappedDelegateExpression)?.expression is FirLazyExpression
|
||||
|| firProperty.getExplicitBackingField()?.initializer is FirLazyExpression
|
||||
}
|
||||
|
||||
private object FirLazyBodiesCalculatorTransformer : FirTransformer<MutableList<FirDeclaration>>() {
|
||||
|
||||
+12
@@ -165,6 +165,18 @@ public class FirLazyBodiesCalculatorTestGenerated extends AbstractFirLazyBodiesC
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyWithBackingField.kt")
|
||||
public void testPropertyWithBackingField() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("propertyWithBackingFieldDifferentTypes.kt")
|
||||
public void testPropertyWithBackingFieldDifferentTypes() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingFieldDifferentTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user