[LL FIR] correctly calculate lazy bodies for delegated properties

We should rebind symbols from generated constructions to the original
ones as we already did for regular bodies like (PsiRawFirBuilder.bindFunctionTarget).
This commit also removed bodies for generated accessors as a bonus

^KT-61491 Fixed
This commit is contained in:
Dmitrii Gridin
2023-10-31 14:02:29 +01:00
committed by Space Team
parent 680455b162
commit 38524f6b15
20 changed files with 635 additions and 791 deletions
@@ -2057,9 +2057,9 @@ open class PsiRawFirBuilder(
expression = delegateExpression
}
val lazyDelegateExpression: FirLazyExpression? = buildOrLazy(
build = { null },
lazy = { buildLazyExpression { source = delegateBuilder.source } },
val (lazyDelegateExpression: FirLazyExpression?, lazyBody: FirLazyBlock?) = buildOrLazy(
build = { null to null },
lazy = { buildLazyExpression { source = delegateBuilder.source } to buildLazyBlock() },
)
generateAccessorsByDelegate(
@@ -2069,6 +2069,7 @@ open class PsiRawFirBuilder(
context,
isExtension = receiverTypeReference != null,
lazyDelegateExpression = lazyDelegateExpression,
lazyBodyForGeneratedAccessors = lazyBody,
)
}
}
@@ -25,9 +25,7 @@ FILE: annotationOnField.kt
protected get(): String
field:@FIELD:Ann() protected final? val delegatedProperty: Stringby LAZY_EXPRESSION
protected get(): <implicit> {
^ this@R|/SomeClass|.D|/SomeClass.delegatedProperty|.getValue#(this@R|/SomeClass|, ::R|/SomeClass.delegatedProperty|)
}
protected get(): <implicit> { LAZY_BLOCK }
field:@FIELD:Ann() public? final? val propertyWithCustomGetter: Int
public? get(): Int { LAZY_BLOCK }
@@ -1,21 +1,13 @@
FILE: delegates.kt
public? final? val x: Intby LAZY_EXPRESSION
public? get(): <implicit> {
^ D|/x|.getValue#(Null(null), ::R|/x|)
}
public? get(): <implicit> { LAZY_BLOCK }
public? final? val delegate: <implicit> = LAZY_EXPRESSION
public? get(): <implicit>
public? final? val value: <implicit>by LAZY_EXPRESSION
public? get(): <implicit> {
^ D|/value|.getValue#(Null(null), ::R|/value|)
}
public? get(): <implicit> { LAZY_BLOCK }
public? final? var variable: <implicit>by LAZY_EXPRESSION
public? get(): <implicit> {
^ D|/variable|.getValue#(Null(null), ::R|/variable|)
}
public? set(<set-?>: <implicit>): R|kotlin/Unit| {
^ D|/variable|.setValue#(Null(null), ::R|/variable|, R|<local>/variable|)
}
public? get(): <implicit> { LAZY_BLOCK }
public? set(<set-?>: <implicit>): R|kotlin/Unit| { LAZY_BLOCK }
public? final? interface Base : R|kotlin/Any| {
}
public? final? class Derived : Base {
@@ -1,5 +1,3 @@
FILE: localDeclarationWithExpression.kt
private final? val nonLocalProperty: List<XXX>by LAZY_EXPRESSION
private get(): <implicit> {
^ D|/nonLocalProperty|.getValue#(Null(null), ::R|/nonLocalProperty|)
}
private get(): <implicit> { LAZY_BLOCK }
@@ -334,6 +334,7 @@ fun <T> FirPropertyBuilder.generateAccessorsByDelegate(
context: Context<T>,
isExtension: Boolean,
lazyDelegateExpression: FirLazyExpression? = null,
lazyBodyForGeneratedAccessors: FirLazyBlock? = null,
) {
if (delegateBuilder == null) return
val delegateFieldSymbol = FirDelegateFieldSymbol(symbol.callableId).also {
@@ -460,8 +461,7 @@ fun <T> FirPropertyBuilder.generateAccessorsByDelegate(
isInline = getterStatus?.isInline ?: isInline
}
symbol = FirPropertyAccessorSymbol()
body = FirSingleExpressionBlock(
body = lazyBodyForGeneratedAccessors ?: FirSingleExpressionBlock(
buildReturnExpression {
result = buildFunctionCall {
source = fakeSource
@@ -518,7 +518,7 @@ fun <T> FirPropertyBuilder.generateAccessorsByDelegate(
}
}
valueParameters += parameter
body = FirSingleExpressionBlock(
body = lazyBodyForGeneratedAccessors ?: FirSingleExpressionBlock(
buildReturnExpression {
result = buildFunctionCall {
source = fakeSource
@@ -1,7 +1,4 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// IGNORE_DIAGNOSTIC_API
// IGNORE_REVERSED_RESOLVE
// ^KT-61491
import kotlin.reflect.KProperty
@@ -1,7 +1,4 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// IGNORE_DIAGNOSTIC_API
// IGNORE_REVERSED_RESOLVE
// ^KT-61491
import kotlin.reflect.KProperty