From 80fda25c583b23314a674c72c29af086196a5ce7 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Fri, 20 Oct 2023 12:29:01 +0200 Subject: [PATCH] [Analysis API] fix common code resolution which requires `FirSyntheticPropertiesStorage` Added test `FirSourceLazyDeclarationResolveTestGenerated.Classes.testClassDelegatedInCommonCode` now fails with another exception (KT-62772). It's fixed in the following commit. ^KT-62768 fixed --- .../fir/sessions/LLFirCommonSessionFactory.kt | 14 +- .../classes/classDelegatedInCommonCode.kt | 9 + .../classes/classDelegatedInCommonCode.txt | 209 ++++++++++++++++++ ...otLazyDeclarationResolveTestGenerated.java | 6 + ...ceLazyDeclarationResolveTestGenerated.java | 6 + 5 files changed, 234 insertions(+), 10 deletions(-) create mode 100644 analysis/low-level-api-fir/testData/lazyResolve/classes/classDelegatedInCommonCode.kt create mode 100644 analysis/low-level-api-fir/testData/lazyResolve/classes/classDelegatedInCommonCode.txt diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/LLFirCommonSessionFactory.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/LLFirCommonSessionFactory.kt index fe7af2499d7..7dd791ad1a0 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/LLFirCommonSessionFactory.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/sessions/LLFirCommonSessionFactory.kt @@ -32,12 +32,13 @@ import org.jetbrains.kotlin.fir.session.DefaultCallConflictResolverFactory import org.jetbrains.kotlin.platform.has import org.jetbrains.kotlin.platform.jvm.JvmPlatform import org.jetbrains.kotlin.utils.addIfNotNull +import org.jetbrains.kotlin.fir.session.FirSessionFactoryHelper.registerDefaultComponents @OptIn(SessionConfiguration::class) internal class LLFirCommonSessionFactory(project: Project) : LLFirAbstractSessionFactory(project) { override fun createSourcesSession(module: KtSourceModule): LLFirSourcesSession { return doCreateSourcesSession(module) { context -> - registerModuleIndependentCommonComponents() + registerDefaultComponents() register( FirSymbolProvider::class, @@ -56,7 +57,7 @@ internal class LLFirCommonSessionFactory(project: Project) : LLFirAbstractSessio override fun createLibrarySession(module: KtModule): LLFirLibraryOrLibrarySourceResolvableModuleSession { return doCreateLibrarySession(module) { context -> - registerModuleIndependentCommonComponents() + registerDefaultComponents() register( FirSymbolProvider::class, @@ -75,7 +76,7 @@ internal class LLFirCommonSessionFactory(project: Project) : LLFirAbstractSessio override fun createBinaryLibrarySession(module: KtBinaryModule): LLFirLibrarySession { return doCreateBinaryLibrarySession(module) { - registerModuleIndependentCommonComponents() + registerDefaultComponents() registerPlatformSpecificComponentsIfAny(module) } } @@ -108,13 +109,6 @@ internal class LLFirCommonSessionFactory(project: Project) : LLFirAbstractSessio } } - private fun LLFirSession.registerModuleIndependentCommonComponents() { - register(FirVisibilityChecker::class, FirVisibilityChecker.Default) - register(ConeCallConflictResolverFactory::class, DefaultCallConflictResolverFactory) - register(FirPlatformClassMapper::class, FirPlatformClassMapper.Default) - register(FirOverridesBackwardCompatibilityHelper::class, FirJvmOverridesBackwardCompatibilityHelper) - } - private fun LLFirSession.registerPlatformSpecificComponentsIfAny(module: KtModule) { if (module.platform.has()) register(FirJvmTypeMapper::class, FirJvmTypeMapper(this)) diff --git a/analysis/low-level-api-fir/testData/lazyResolve/classes/classDelegatedInCommonCode.kt b/analysis/low-level-api-fir/testData/lazyResolve/classes/classDelegatedInCommonCode.kt new file mode 100644 index 00000000000..4b58f0b0a20 --- /dev/null +++ b/analysis/low-level-api-fir/testData/lazyResolve/classes/classDelegatedInCommonCode.kt @@ -0,0 +1,9 @@ +// TARGET_PLATFORM: Common + +public class AA( + private val content: Map +) : Map by content { + override fun toString(): String { + return content.entries.toString() + } +} \ No newline at end of file diff --git a/analysis/low-level-api-fir/testData/lazyResolve/classes/classDelegatedInCommonCode.txt b/analysis/low-level-api-fir/testData/lazyResolve/classes/classDelegatedInCommonCode.txt new file mode 100644 index 00000000000..9f1af49b303 --- /dev/null +++ b/analysis/low-level-api-fir/testData/lazyResolve/classes/classDelegatedInCommonCode.txt @@ -0,0 +1,209 @@ +RAW_FIR: +FILE: [ResolvedTo(RAW_FIR)] classDelegatedInCommonCode.kt + public final? [ResolvedTo(RAW_FIR)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : Map { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +IMPORTS: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final? [ResolvedTo(RAW_FIR)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : Map { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +COMPILER_REQUIRED_ANNOTATIONS: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final? [ResolvedTo(COMPILER_REQUIRED_ANNOTATIONS)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : Map { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +COMPANION_GENERATION: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final? [ResolvedTo(COMPANION_GENERATION)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : Map { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +SUPER_TYPES: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final? [ResolvedTo(SUPER_TYPES)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : R|kotlin/collections/Map| { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +TYPES: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final? [ResolvedTo(TYPES)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : R|kotlin/collections/Map| { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +STATUS: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final [ResolvedTo(STATUS)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : R|kotlin/collections/Map| { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +EXPECT_ACTUAL_MATCHING: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final [ResolvedTo(EXPECT_ACTUAL_MATCHING)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : R|kotlin/collections/Map| { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +CONTRACTS: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final [ResolvedTo(CONTRACTS)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : R|kotlin/collections/Map| { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +IMPLICIT_TYPES_BODY_RESOLVE: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : R|kotlin/collections/Map| { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +ANNOTATION_ARGUMENTS: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final [ResolvedTo(ANNOTATION_ARGUMENTS)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : R|kotlin/collections/Map| { + public? [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] constructor([ResolvedTo(RAW_FIR)] [CorrespondingProperty=/AA.content] content: Map): R|AA| { + LAZY_super<> + } + + private final [ResolvedTo(RAW_FIR)] field $$delegate_0: Map = LAZY_EXPRESSION + + private final? [ResolvedTo(RAW_FIR)] [IsFromPrimaryConstructor=true] val content: Map = R|/content| + private [ResolvedTo(RAW_FIR)] [ContainingClassKey=AA] get(): Map + + public? open? override [ResolvedTo(RAW_FIR)] fun toString(): String { LAZY_BLOCK } + + } + +BODY_RESOLVE: +FILE: [ResolvedTo(IMPORTS)] classDelegatedInCommonCode.kt + public final [ResolvedTo(BODY_RESOLVE)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : R|kotlin/collections/Map| { + public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=AA] constructor([ResolvedTo(BODY_RESOLVE)] [CorrespondingProperty=/AA.content] content: R|kotlin/collections/Map|): R|AA| { + super() + } + + private final [ResolvedTo(BODY_RESOLVE)] field $$delegate_0: R|kotlin/collections/Map| = R|/content| + + private final [ResolvedTo(BODY_RESOLVE)] [IsFromPrimaryConstructor=true] val content: R|kotlin/collections/Map| = R|/content| + private [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=AA] get(): R|kotlin/collections/Map| + + public open override [ResolvedTo(STATUS)] fun toString(): R|kotlin/String| { LAZY_BLOCK } + + } + +FILE RAW TO BODY: +FILE: [ResolvedTo(BODY_RESOLVE)] classDelegatedInCommonCode.kt + public final [ResolvedTo(BODY_RESOLVE)] [DelegateFieldsMapKey={0=FirFieldSymbol /AA.$$delegate_0}] class AA : R|kotlin/collections/Map| { + public [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=AA] constructor([ResolvedTo(BODY_RESOLVE)] [CorrespondingProperty=/AA.content] content: R|kotlin/collections/Map|): R|AA| { + super() + } + + private final [ResolvedTo(BODY_RESOLVE)] field $$delegate_0: R|kotlin/collections/Map| = R|/content| + + private final [ResolvedTo(BODY_RESOLVE)] [IsFromPrimaryConstructor=true] val content: R|kotlin/collections/Map| = R|/content| + private [ResolvedTo(BODY_RESOLVE)] [ContainingClassKey=AA] get(): R|kotlin/collections/Map| + + public open override [ResolvedTo(BODY_RESOLVE)] fun toString(): R|kotlin/String| { + ^toString this@R|/AA|.R|/AA.content|.R|SubstitutionOverride>|>|.R|kotlin/Any.toString|() + } + + } diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyDeclarationResolveTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyDeclarationResolveTestGenerated.java index ba8c60c9404..0901fb27938 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyDeclarationResolveTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirOutOfContentRootLazyDeclarationResolveTestGenerated.java @@ -645,6 +645,12 @@ public class FirOutOfContentRootLazyDeclarationResolveTestGenerated extends Abst runTest("analysis/low-level-api-fir/testData/lazyResolve/classes/annotationWithTarget.kt"); } + @Test + @TestMetadata("classDelegatedInCommonCode.kt") + public void testClassDelegatedInCommonCode() throws Exception { + runTest("analysis/low-level-api-fir/testData/lazyResolve/classes/classDelegatedInCommonCode.kt"); + } + @Test @TestMetadata("classWithTypeParameters.kt") public void testClassWithTypeParameters() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyDeclarationResolveTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyDeclarationResolveTestGenerated.java index e88e1b66e7b..61345cc0ec0 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyDeclarationResolveTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/FirSourceLazyDeclarationResolveTestGenerated.java @@ -645,6 +645,12 @@ public class FirSourceLazyDeclarationResolveTestGenerated extends AbstractFirSou runTest("analysis/low-level-api-fir/testData/lazyResolve/classes/annotationWithTarget.kt"); } + @Test + @TestMetadata("classDelegatedInCommonCode.kt") + public void testClassDelegatedInCommonCode() throws Exception { + runTest("analysis/low-level-api-fir/testData/lazyResolve/classes/classDelegatedInCommonCode.kt"); + } + @Test @TestMetadata("classWithTypeParameters.kt") public void testClassWithTypeParameters() throws Exception {