Add tests for JVM backend diagnostics with K2 light tree
In the vast majority of tests, diagnostics are reported at a slightly different location in LT vs PSI. This is because in the light tree mode, backend errors are reported basically on the start of the IR element, which is for example the keyword "class" for a class and not its name as in K1 or in K2+PSI. Similarly, the end of the diagnostic is at the ending offset of the IR element. Normally it would be a bit user-unfriendly to highlight the whole class as red, starting from the keyword "class" and ending with the closing brace "}". But remember that these are backend diagnostics in the K2+LT mode, which is only possible in the compiler scenario, not in the IDE. And in this case, the ending offset doesn't matter at all because it's not presented to the user, and minor change in the starting offset is not a problem as well. There are some tests which legitimately fail in the LT mode because the corresponding diagnostics haven't been supported. They will be dealt with in subsequent commits: testPropertyInlineCycle testInlineCycle MultifileClasses.testJvmSynthetic testSuspendInlineCycle testIndirectInlineCycle #KT-59586
This commit is contained in:
+7
-2
@@ -15,7 +15,10 @@ import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticsCollector
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.KtDefaultJvmErrorMessages
|
||||
import org.jetbrains.kotlin.test.FirParser
|
||||
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.singleOrZeroValue
|
||||
import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticReporter
|
||||
import org.jetbrains.kotlin.test.frontend.classic.handlers.withNewInferenceModeEnabled
|
||||
import org.jetbrains.kotlin.test.frontend.fir.handlers.FirDiagnosticCodeMetaInfo
|
||||
@@ -57,11 +60,13 @@ class JvmBackendDiagnosticsHandler(testServices: TestServices) : JvmBinaryArtifa
|
||||
private fun reportKtDiagnostics(module: TestModule, info: BinaryArtifacts.Jvm) {
|
||||
val ktDiagnosticReporter = info.classFileFactory.generationState.diagnosticReporter as BaseDiagnosticsCollector
|
||||
val globalMetadataInfoHandler = testServices.globalMetadataInfoHandler
|
||||
val firParser = module.directives.singleOrZeroValue(FirDiagnosticsDirectives.FIR_PARSER)
|
||||
val lightTreeComparingModeEnabled = firParser != null && FirDiagnosticsDirectives.COMPARE_WITH_LIGHT_TREE in module.directives
|
||||
val lightTreeEnabled = firParser == FirParser.LightTree
|
||||
for (testFile in module.files) {
|
||||
val ktDiagnostics = ktDiagnosticReporter.diagnosticsByFilePath["/${testFile.name}"] ?: continue
|
||||
ktDiagnostics.forEach {
|
||||
val metaInfos =
|
||||
it.toMetaInfos(module, testFile, globalMetadataInfoHandler, false, false)
|
||||
val metaInfos = it.toMetaInfos(module, testFile, globalMetadataInfoHandler, lightTreeEnabled, lightTreeComparingModeEnabled)
|
||||
globalMetadataInfoHandler.addMetadataInfosForFile(testFile, metaInfos)
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.test.frontend.fir.Fir2IrJvmResultsConverter
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact
|
||||
import org.jetbrains.kotlin.test.frontend.fir.handlers.FirDiagnosticsHandler
|
||||
import org.jetbrains.kotlin.test.frontend.fir.handlers.PsiLightTreeMetaInfoProcessor
|
||||
import org.jetbrains.kotlin.test.model.*
|
||||
import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator
|
||||
import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator
|
||||
@@ -63,6 +64,7 @@ abstract class AbstractDiagnosticsTestWithJvmBackend<R : ResultingArtifact.Front
|
||||
)
|
||||
|
||||
useMetaInfoProcessors(::OldNewInferenceMetaInfoProcessor)
|
||||
|
||||
useAdditionalSourceProviders(
|
||||
::AdditionalDiagnosticsSourceFilesProvider,
|
||||
::CoroutineHelpersSourceFilesProvider,
|
||||
@@ -77,6 +79,7 @@ abstract class AbstractDiagnosticsTestWithJvmBackend<R : ResultingArtifact.Front
|
||||
)
|
||||
}
|
||||
} else {
|
||||
useMetaInfoProcessors(::PsiLightTreeMetaInfoProcessor)
|
||||
firHandlersStep {
|
||||
useHandlers(::FirDiagnosticsHandler)
|
||||
}
|
||||
@@ -132,3 +135,5 @@ abstract class AbstractFirDiagnosticsTestWithJvmIrBackendBase(
|
||||
}
|
||||
|
||||
abstract class AbstractFirPsiDiagnosticsTestWithJvmIrBackend : AbstractFirDiagnosticsTestWithJvmIrBackendBase(FirParser.Psi)
|
||||
|
||||
abstract class AbstractFirLightTreeDiagnosticsTestWithJvmIrBackend : AbstractFirDiagnosticsTestWithJvmIrBackendBase(FirParser.LightTree)
|
||||
|
||||
Reference in New Issue
Block a user