[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
This commit is contained in:
Anna Kozlova
2023-02-03 12:11:57 +01:00
committed by teamcity
parent 3772d60ca6
commit 71a1585240
@@ -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.