diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/DiagnosticsDirectives.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/DiagnosticsDirectives.kt index 18b95105706..d21e04f13ea 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/DiagnosticsDirectives.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/DiagnosticsDirectives.kt @@ -70,4 +70,11 @@ object DiagnosticsDirectives : SimpleDirectivesContainer() { (additional to root package) """.trimIndent() ) + + val REPORT_ONLY_EXPLICITLY_DEFINED_DEBUG_INFO by directive( + description = """ + If this directive enabled then `DEBUG_INFO_...` diagnostics will be reported + only if they are defined in testdata. + """.trimIndent() + ) } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/ClassicDiagnosticsHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/ClassicDiagnosticsHandler.kt index 798d7d4a29a..4c4b9cf8ae8 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/ClassicDiagnosticsHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/handlers/ClassicDiagnosticsHandler.kt @@ -119,9 +119,13 @@ class ClassicDiagnosticsHandler(testServices: TestServices) : ClassicFrontendAna info.analysisResult.moduleDescriptor as ModuleDescriptorImpl, diagnosedRanges = diagnosedRanges ) - debugAnnotations.mapNotNull { debugAnnotation -> + val onlyExplicitlyDefined = DiagnosticsDirectives.REPORT_ONLY_EXPLICITLY_DEFINED_DEBUG_INFO in module.directives + for (debugAnnotation in debugAnnotations) { val factory = debugAnnotation.diagnostic.factory - if (!diagnosticsService.shouldRenderDiagnostic(module, factory.name, factory.severity)) return@mapNotNull null + if (!diagnosticsService.shouldRenderDiagnostic(module, factory.name, factory.severity)) continue + if (onlyExplicitlyDefined && !debugAnnotation.diagnostic.textRanges.any { it.startOffset..it.endOffset in diagnosedRanges }) { + continue + } reporter.reportDiagnostic(debugAnnotation.diagnostic, module, file, configuration, withNewInferenceModeEnabled) } }