From 71a1585240415a9174b3c26a5ccb17587423f649 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 3 Feb 2023 12:11:57 +0100 Subject: [PATCH] [LL] add assertion that module of ktFile and FirBuilder are equivalent to catch KTIJ-24530, when file was located in production scope of the module but fir was created both for the test source and production --- .../level/api/fir/file/builder/LLFirFileBuilder.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/file/builder/LLFirFileBuilder.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/file/builder/LLFirFileBuilder.kt index 9093a55c519..2cc81888a92 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/file/builder/LLFirFileBuilder.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/file/builder/LLFirFileBuilder.kt @@ -7,8 +7,10 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder import org.jetbrains.kotlin.analysis.api.impl.barebone.annotations.ThreadSafe import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirModuleResolveComponents -import org.jetbrains.kotlin.fir.builder.RawFirBuilder +import org.jetbrains.kotlin.analysis.project.structure.getKtModule +import org.jetbrains.kotlin.analysis.utils.errors.checkWithAttachmentBuilder import org.jetbrains.kotlin.fir.builder.BodyBuildingMode +import org.jetbrains.kotlin.fir.builder.RawFirBuilder import org.jetbrains.kotlin.fir.declarations.FirFile import org.jetbrains.kotlin.psi.KtFile @@ -20,6 +22,15 @@ internal class LLFirFileBuilder( val moduleComponents: LLFirModuleResolveComponents, ) { fun buildRawFirFileWithCaching(ktFile: KtFile): FirFile = moduleComponents.cache.fileCached(ktFile) { + checkWithAttachmentBuilder(ktFile.getKtModule() == moduleComponents.module, { "Modules are inconsistent" }) { + withEntry("file", ktFile.name) + withEntry("file module", ktFile.getKtModule()) { + it.toString() + } + withEntry("components module", moduleComponents.module) { + it.toString() + } + } val bodyBuildingMode = when { ktFile.isScript() -> { // As 'FirScript' content is never transformed, lazy bodies are not replaced with calculated ones even on BODY_RESOLVE.