FIR: add test which checks that we do not access lazy bodies & lazy expressions till contract phase
This commit is contained in:
+2669
File diff suppressed because it is too large
Load Diff
+9
-1
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.diagnostics.PsiDiagnosticUtils
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirPsiDiagnostic
|
||||
import org.jetbrains.kotlin.fir.builder.RawFirBuilder
|
||||
import org.jetbrains.kotlin.fir.builder.RawFirBuilderMode
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.extensions.BunchOfRegisteredExtensions
|
||||
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
||||
@@ -56,6 +57,9 @@ abstract class AbstractFirBaseDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
protected open val useLightTree: Boolean
|
||||
get() = false
|
||||
|
||||
protected open val useLazyBodiesModeForRawFir: Boolean
|
||||
get() = false
|
||||
|
||||
override fun setupEnvironment(environment: KotlinCoreEnvironment) {
|
||||
PsiElementFinder.EP.getPoint(environment.project).unregisterExtension(JavaElementFinder::class.java)
|
||||
}
|
||||
@@ -118,7 +122,11 @@ abstract class AbstractFirBaseDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
firFile
|
||||
}
|
||||
} else {
|
||||
val firBuilder = RawFirBuilder(session, firProvider.kotlinScopeProvider)
|
||||
val firBuilder = RawFirBuilder(
|
||||
session,
|
||||
firProvider.kotlinScopeProvider,
|
||||
RawFirBuilderMode.lazyBodies(useLazyBodiesModeForRawFir)
|
||||
)
|
||||
ktFiles.mapTo(firFiles) {
|
||||
val firFile = firBuilder.buildFirFile(it)
|
||||
firProvider.recordFile(firFile)
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.createCompilerProcessorByPhase
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractLazyBodyIsNotTouchedTilContractsPhaseTest : AbstractFirBaseDiagnosticsTest() {
|
||||
override val useLazyBodiesModeForRawFir: Boolean get() = true
|
||||
|
||||
override fun runAnalysis(testDataFile: File, testFiles: List<TestFile>, firFilesPerSession: Map<FirSession, List<FirFile>>) {
|
||||
val phases = FirResolvePhase.values().filter { phase -> phase != FirResolvePhase.RAW_FIR && phase < FirResolvePhase.CONTRACTS }
|
||||
for ((session, firFiles) in firFilesPerSession) {
|
||||
val scopeSession = ScopeSession()
|
||||
/*
|
||||
Test that we are not touching lazy bodies & lazy expressions during phases < CONTRACTS
|
||||
If we try to access them, the exception will be thrown and test will fail
|
||||
*/
|
||||
doFirResolveTestBench(
|
||||
firFiles,
|
||||
phases.map { it.createCompilerProcessorByPhase(session, scopeSession) },
|
||||
gc = false
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -610,6 +610,11 @@ fun main(args: Array<String>) {
|
||||
testClass<AbstractFirDiagnosticsWithLightTreeTest> {
|
||||
model("resolve", pattern = KT_WITHOUT_DOTS_IN_NAME)
|
||||
}
|
||||
|
||||
testClass<AbstractLazyBodyIsNotTouchedTilContractsPhaseTest> {
|
||||
model("resolve", pattern = KT_WITHOUT_DOTS_IN_NAME)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
testGroup("compiler/fir/analysis-tests/tests", "compiler/fir/analysis-tests/testData") {
|
||||
|
||||
Reference in New Issue
Block a user