From 0f6a51fd97806edeee790f01d19a8a261d40fb02 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Tue, 8 Aug 2023 10:15:35 +0200 Subject: [PATCH] K2: Adjust lazy test data after delegate inference rewritten It's been changed because `getValue` might be not completed after exiting from call transformation while contracts processing seems to be working only with completed calls ^KT-61055 Related --- .../testdata/lazyResolve/lazyProperty.txt | 12 +++--------- .../testdata/lazyResolve/lazyPropertyScript.txt | 12 +++--------- .../kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt | 3 +++ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/analysis/low-level-api-fir/testdata/lazyResolve/lazyProperty.txt b/analysis/low-level-api-fir/testdata/lazyResolve/lazyProperty.txt index 153ef7410bc..b889e181488 100644 --- a/analysis/low-level-api-fir/testdata/lazyResolve/lazyProperty.txt +++ b/analysis/low-level-api-fir/testdata/lazyResolve/lazyProperty.txt @@ -291,9 +291,7 @@ FILE: [ResolvedTo(IMPORTS)] lazyProperty.kt public final [ResolvedTo(STATUS)] [IsFromPrimaryConstructor=true] val value: R|T| = R|/value| public [ResolvedTo(STATUS)] [ContainingClassKey=LazyDelegate] get(): R|T| - public final operator [ResolvedTo(CONTRACTS)] fun getValue([ResolvedTo(CONTRACTS)] thisRef: R|kotlin/Any?|, [ResolvedTo(CONTRACTS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { - ^getValue value# - } + public final operator [ResolvedTo(STATUS)] fun getValue([ResolvedTo(STATUS)] thisRef: R|kotlin/Any?|, [ResolvedTo(STATUS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { LAZY_BLOCK } } public final [ResolvedTo(CONTRACTS)] fun <[ResolvedTo(CONTRACTS)] T> lazy([ResolvedTo(CONTRACTS)] block: R|() -> T|): R|LazyDelegate| { @@ -328,9 +326,7 @@ FILE: [ResolvedTo(IMPORTS)] lazyProperty.kt public final [ResolvedTo(STATUS)] [IsFromPrimaryConstructor=true] val value: R|T| = R|/value| public [ResolvedTo(STATUS)] [ContainingClassKey=LazyDelegate] get(): R|T| - public final operator [ResolvedTo(CONTRACTS)] fun getValue([ResolvedTo(CONTRACTS)] thisRef: R|kotlin/Any?|, [ResolvedTo(CONTRACTS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { - ^getValue value# - } + public final operator [ResolvedTo(STATUS)] fun getValue([ResolvedTo(STATUS)] thisRef: R|kotlin/Any?|, [ResolvedTo(STATUS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { LAZY_BLOCK } } public final [ResolvedTo(CONTRACTS)] fun <[ResolvedTo(CONTRACTS)] T> lazy([ResolvedTo(CONTRACTS)] block: R|() -> T|): R|LazyDelegate| { @@ -365,9 +361,7 @@ FILE: [ResolvedTo(IMPORTS)] lazyProperty.kt public final [ResolvedTo(STATUS)] [IsFromPrimaryConstructor=true] val value: R|T| = R|/value| public [ResolvedTo(STATUS)] [ContainingClassKey=LazyDelegate] get(): R|T| - public final operator [ResolvedTo(CONTRACTS)] fun getValue([ResolvedTo(CONTRACTS)] thisRef: R|kotlin/Any?|, [ResolvedTo(CONTRACTS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { - ^getValue value# - } + public final operator [ResolvedTo(STATUS)] fun getValue([ResolvedTo(STATUS)] thisRef: R|kotlin/Any?|, [ResolvedTo(STATUS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { LAZY_BLOCK } } public final [ResolvedTo(CONTRACTS)] fun <[ResolvedTo(CONTRACTS)] T> lazy([ResolvedTo(CONTRACTS)] block: R|() -> T|): R|LazyDelegate| { diff --git a/analysis/low-level-api-fir/testdata/lazyResolve/lazyPropertyScript.txt b/analysis/low-level-api-fir/testdata/lazyResolve/lazyPropertyScript.txt index 7f4b167ec3c..9c0882e260a 100644 --- a/analysis/low-level-api-fir/testdata/lazyResolve/lazyPropertyScript.txt +++ b/analysis/low-level-api-fir/testdata/lazyResolve/lazyPropertyScript.txt @@ -385,9 +385,7 @@ FILE: [ResolvedTo(IMPORTS)] lazyPropertyScript.kts public final [ResolvedTo(STATUS)] [IsFromPrimaryConstructor=true] val value: R|T| = R|/value| public [ResolvedTo(STATUS)] [ContainingClassKey=LazyDelegate] get(): R|T| - public final operator [ResolvedTo(CONTRACTS)] fun getValue([ResolvedTo(CONTRACTS)] thisRef: R|kotlin/Any?|, [ResolvedTo(CONTRACTS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { - ^getValue value# - } + public final operator [ResolvedTo(STATUS)] fun getValue([ResolvedTo(STATUS)] thisRef: R|kotlin/Any?|, [ResolvedTo(STATUS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { LAZY_BLOCK } } @@ -431,9 +429,7 @@ FILE: [ResolvedTo(IMPORTS)] lazyPropertyScript.kts public final [ResolvedTo(STATUS)] [IsFromPrimaryConstructor=true] val value: R|T| = R|/value| public [ResolvedTo(STATUS)] [ContainingClassKey=LazyDelegate] get(): R|T| - public final operator [ResolvedTo(CONTRACTS)] fun getValue([ResolvedTo(CONTRACTS)] thisRef: R|kotlin/Any?|, [ResolvedTo(CONTRACTS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { - ^getValue value# - } + public final operator [ResolvedTo(STATUS)] fun getValue([ResolvedTo(STATUS)] thisRef: R|kotlin/Any?|, [ResolvedTo(STATUS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { LAZY_BLOCK } } @@ -477,9 +473,7 @@ FILE: [ResolvedTo(IMPORTS)] lazyPropertyScript.kts public final [ResolvedTo(STATUS)] [IsFromPrimaryConstructor=true] val value: R|T| = R|/value| public [ResolvedTo(STATUS)] [ContainingClassKey=LazyDelegate] get(): R|T| - public final operator [ResolvedTo(CONTRACTS)] fun getValue([ResolvedTo(CONTRACTS)] thisRef: R|kotlin/Any?|, [ResolvedTo(CONTRACTS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { - ^getValue value# - } + public final operator [ResolvedTo(STATUS)] fun getValue([ResolvedTo(STATUS)] thisRef: R|kotlin/Any?|, [ResolvedTo(STATUS)] property: R|kotlin/reflect/KProperty<*>|): R|T| { LAZY_BLOCK } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt index d10abeba25f..3a691a939ab 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt @@ -862,6 +862,9 @@ abstract class FirDataFlowAnalyzer( private fun processConditionalContract(flow: MutableFlow, qualifiedAccess: FirStatement) { // contracts has no effect on non-body resolve stages if (!components.transformer.baseTransformerPhase.isBodyResolve) return + + // TODO: Consider using something besides `toResolvedCallableSymbol` as the latter only works + // for completed calls without candidates (KT-61055 for tracking) val callee = when (qualifiedAccess) { is FirFunctionCall -> qualifiedAccess.toResolvedCallableSymbol()?.fir as? FirSimpleFunction is FirQualifiedAccessExpression -> qualifiedAccess.calleeReference.toResolvedPropertySymbol()?.fir?.getter