From 110cc79ddd3b27e57875dc19b8cbcbad92ed5b47 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Wed, 14 Jun 2023 10:19:21 +0300 Subject: [PATCH] [FIR] Improve debugging of diagnostic ranges `UNREACHABLE_CODE` is weird. If we look into its positioning strategy, we'll see that this diagnostic attempts to split the source of its element into multiple ranges. This is bad, because such smaller ranges can easily overlap with other diagnostics in such a way that they are no longer hierarchical. See the `compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/3.kt` test for an example of this behavior (allow reporting `UNREACHABLE_CODE` first). The problem will appear at the condition of `case_7`. --- .../jetbrains/kotlin/codeMetaInfo/CodeMetaInfoRenderer.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/CodeMetaInfoRenderer.kt b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/CodeMetaInfoRenderer.kt index 4dadb21a64a..412d043c6f6 100644 --- a/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/CodeMetaInfoRenderer.kt +++ b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codeMetaInfo/CodeMetaInfoRenderer.kt @@ -61,6 +61,12 @@ object CodeMetaInfoRenderer { while (current != null) { val next: CodeMetaInfo? = if (iterator.hasNext()) iterator.next() else null + val outer = opened.lastOrNull() + if (outer != null) { + require(current.end <= outer.end) { + "The outer diagnostic ${outer.tag} at ${outer.start} ends at ${outer.end}, but the supposedly inner ${current?.tag} starting at ${current?.start} ends at ${current?.end}. Rendered so far:\n$builder" + } + } opened.push(current) builder.append(current.asString()) when {