FIR LT: Fix diagnostic location calculation on the last line

it was calculated incorrectly on the last line that do not end
with EOL.
#KT-56649 fixed
This commit is contained in:
Ilya Chernikov
2023-02-14 17:06:58 +01:00
committed by Space Team
parent d120d83d60
commit e39eb62e6e
11 changed files with 61 additions and 1 deletions
@@ -166,7 +166,7 @@ private class SequentialFilePositionFinder(file: File) : Closeable {
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)
return if (col <= currentLineContent!!.length + 1 /* accounting for a report on EOL (e.g. syntax errors) */ )
KtSourceFilePos(currentLine, col, if (withLineContents) currentLineContent else null)
else null
}
@@ -195,6 +195,8 @@ private class SequentialFilePositionFinder(file: File) : Closeable {
bufPos = 0
if (bufLength < 0) {
endOfStream = true
currentLine++
charsRead++ // assuming virtual EOL at EOF for calculations
break
}
} else {
+6
View File
@@ -0,0 +1,6 @@
$TESTDATA_DIR$/firErrorOnLastLine.kt
-language-version
2.0
-Xuse-fir-lt=true
-d
$TEMP_DIR$
+2
View File
@@ -0,0 +1,2 @@
val x = this
val y = this // EOL AFTER THIS LINE!
+8
View File
@@ -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/firErrorOnLastLine.kt:1:9: error: 'this' is not defined in this context
val x = this
^
compiler/testData/cli/jvm/firErrorOnLastLine.kt:2:9: error: 'this' is not defined in this context
val y = this // EOL AFTER THIS LINE!
^
COMPILATION_ERROR
@@ -0,0 +1,6 @@
$TESTDATA_DIR$/firErrorOnLastLineNoEol.kt
-language-version
2.0
-Xuse-fir-lt=true
-d
$TEMP_DIR$
+2
View File
@@ -0,0 +1,2 @@
val x = this
val y = this // *NO* EOL AFTER THIS LINE!
+8
View File
@@ -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/firErrorOnLastLineNoEol.kt:1:9: error: 'this' is not defined in this context
val x = this
^
compiler/testData/cli/jvm/firErrorOnLastLineNoEol.kt:2:9: error: 'this' is not defined in this context
val y = this // *NO* EOL AFTER THIS LINE!
^
COMPILATION_ERROR
+5
View File
@@ -0,0 +1,5 @@
$TESTDATA_DIR$/firSyntaxError.kt
-language-version
2.0
-d
$TEMP_DIR$
+1
View File
@@ -0,0 +1 @@
fun a() {
+5
View File
@@ -0,0 +1,5 @@
warning: language version 2.0 is experimental, there are no backwards compatibility guarantees for new language and library features
compiler/testData/cli/jvm/firSyntaxError.kt:1:10: error: syntax error
fun a() {
^
COMPILATION_ERROR
@@ -442,6 +442,16 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/firError.args");
}
@TestMetadata("firErrorOnLastLine.args")
public void testFirErrorOnLastLine() throws Exception {
runTest("compiler/testData/cli/jvm/firErrorOnLastLine.args");
}
@TestMetadata("firErrorOnLastLineNoEol.args")
public void testFirErrorOnLastLineNoEol() throws Exception {
runTest("compiler/testData/cli/jvm/firErrorOnLastLineNoEol.args");
}
@TestMetadata("firHello.args")
public void testFirHello() throws Exception {
runTest("compiler/testData/cli/jvm/firHello.args");
@@ -492,6 +502,11 @@ public class CliTestGenerated extends AbstractCliTest {
runTest("compiler/testData/cli/jvm/firStdlibDependency.args");
}
@TestMetadata("firSyntaxError.args")
public void testFirSyntaxError() throws Exception {
runTest("compiler/testData/cli/jvm/firSyntaxError.args");
}
@TestMetadata("firVsClassicAnnotation.args")
public void testFirVsClassicAnnotation() throws Exception {
runTest("compiler/testData/cli/jvm/firVsClassicAnnotation.args");