[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 {
|
||||
|
||||
+10
@@ -151,6 +151,16 @@ public class LightTree2FirConverterTestCaseGenerated extends AbstractLightTree2F
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyWithBackingField.kt")
|
||||
public void testPropertyWithBackingField() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyWithBackingFieldDifferentTypes.kt")
|
||||
public void testPropertyWithBackingFieldDifferentTypes() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingFieldDifferentTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/simpleClass.kt");
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun resolveMe() {
|
||||
receive(property)
|
||||
}
|
||||
|
||||
val property: Int
|
||||
field: Int = 10
|
||||
|
||||
fun receive(s: Int) {}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
FILE: propertyWithBackingField.kt
|
||||
public? final? fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
public? final? val property: Int
|
||||
private <explicit backing field>: Int = LAZY_EXPRESSION
|
||||
public? get(): Int
|
||||
public? final? fun receive(s: Int): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
FILE: propertyWithBackingField.kt
|
||||
public? final? fun resolveMe(): R|kotlin/Unit| {
|
||||
receive#(property#)
|
||||
}
|
||||
public? final? val property: Int
|
||||
private <explicit backing field>: Int = IntegerLiteral(10)
|
||||
public? get(): Int
|
||||
public? final? fun receive(s: Int): R|kotlin/Unit| {
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun resolveMe() {
|
||||
receive(property)
|
||||
}
|
||||
|
||||
val property: Number
|
||||
field: Int = 10
|
||||
|
||||
fun receive(s: Int) {}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
FILE: propertyWithBackingFieldDifferentTypes.kt
|
||||
public? final? fun resolveMe(): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
public? final? val property: Number
|
||||
private <explicit backing field>: Int = LAZY_EXPRESSION
|
||||
public? get(): Number
|
||||
public? final? fun receive(s: Int): R|kotlin/Unit| { LAZY_BLOCK }
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
FILE: propertyWithBackingFieldDifferentTypes.kt
|
||||
public? final? fun resolveMe(): R|kotlin/Unit| {
|
||||
receive#(property#)
|
||||
}
|
||||
public? final? val property: Number
|
||||
private <explicit backing field>: Int = IntegerLiteral(10)
|
||||
public? get(): Number
|
||||
public? final? fun receive(s: Int): R|kotlin/Unit| {
|
||||
}
|
||||
+10
@@ -151,6 +151,16 @@ public class RawFirBuilderLazyBodiesTestCaseGenerated extends AbstractRawFirBuil
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyWithBackingField.kt")
|
||||
public void testPropertyWithBackingField() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyWithBackingFieldDifferentTypes.kt")
|
||||
public void testPropertyWithBackingFieldDifferentTypes() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingFieldDifferentTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/simpleClass.kt");
|
||||
|
||||
+10
@@ -151,6 +151,16 @@ public class RawFirBuilderTestCaseGenerated extends AbstractRawFirBuilderTestCas
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyWithBackingField.kt")
|
||||
public void testPropertyWithBackingField() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyWithBackingFieldDifferentTypes.kt")
|
||||
public void testPropertyWithBackingFieldDifferentTypes() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/propertyWithBackingFieldDifferentTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
runTest("compiler/fir/raw-fir/psi2fir/testData/rawBuilder/declarations/simpleClass.kt");
|
||||
|
||||
+12
@@ -165,6 +165,18 @@ public class FirVisualizerForRawFirDataGenerated extends AbstractFirVisualizerTe
|
||||
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 {
|
||||
|
||||
+12
@@ -165,6 +165,18 @@ public class PsiVisualizerForRawFirDataGenerated extends AbstractPsiVisualizerTe
|
||||
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