From 7ec72b568da653a1f4863c7769778f367eb45d4a Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Thu, 19 Jan 2023 15:35:34 +0100 Subject: [PATCH] Fix assertion in light tree diagnostic reporter happened then two diagnostics are reported on the same element. #KT-55924 fixed --- .../fir/FirDiagnosticsCompilerResultsReporter.kt | 2 +- .../cli/jvm/twoDiagnosticsOnSingleElement.args | 6 ++++++ .../testData/cli/jvm/twoDiagnosticsOnSingleElement.kt | 11 +++++++++++ .../cli/jvm/twoDiagnosticsOnSingleElement.out | 8 ++++++++ .../org/jetbrains/kotlin/cli/CliTestGenerated.java | 5 +++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.args create mode 100644 compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.kt create mode 100644 compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.out diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/fir/FirDiagnosticsCompilerResultsReporter.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/fir/FirDiagnosticsCompilerResultsReporter.kt index f8e09bc01d6..49d416d1915 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/fir/FirDiagnosticsCompilerResultsReporter.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/fir/FirDiagnosticsCompilerResultsReporter.kt @@ -162,10 +162,10 @@ private class SequentialFilePositionFinder(file: File) : Closeable { // assuming that if called multiple times, calls should be sorted by ascending offset fun findNextPosition(offset: Int, withLineContents: Boolean = true): KtSourceFilePos { - assert(offset >= charsRead - (currentLineContent?.length ?: 0)) fun posInCurrentLine(): KtSourceFilePos? { val col = offset - (charsRead - currentLineContent!!.length - 1)/* beginning of line offset */ + 1 /* col is 1-based */ + assert(col > 0) return if (col <= currentLineContent!!.length) KtSourceFilePos(currentLine, col, if (withLineContents) currentLineContent else null) else null diff --git a/compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.args b/compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.args new file mode 100644 index 00000000000..893b923e9cf --- /dev/null +++ b/compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.args @@ -0,0 +1,6 @@ +-Xuse-fir-lt=true +-language-version +2.0 +$TESTDATA_DIR$/twoDiagnosticsOnSingleElement.kt +-d +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.kt b/compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.kt new file mode 100644 index 00000000000..aee32a6d993 --- /dev/null +++ b/compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.kt @@ -0,0 +1,11 @@ +package test + +interface I1 { + fun foo() +} + +interface I2 { + fun foo() +} + +class C : I1, I2 diff --git a/compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.out b/compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.out new file mode 100644 index 00000000000..1089d051f47 --- /dev/null +++ b/compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.out @@ -0,0 +1,8 @@ +warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features +compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.kt:11:1: error: class C is not abstract and does not implement abstract member foo +class C : I1, I2 +^ +compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.kt:11:1: error: c inherits conflicting members: foo, foo +class C : I1, I2 +^ +COMPILATION_ERROR \ No newline at end of file diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 6b57f696488..2632ff6fa42 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -1077,6 +1077,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/syntheticAccessorSignatureClash.args"); } + @TestMetadata("twoDiagnosticsOnSingleElement.args") + public void testTwoDiagnosticsOnSingleElement() throws Exception { + runTest("compiler/testData/cli/jvm/twoDiagnosticsOnSingleElement.args"); + } + @TestMetadata("unknownExtraFlags.args") public void testUnknownExtraFlags() throws Exception { runTest("compiler/testData/cli/jvm/unknownExtraFlags.args");