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 49d416d1915..6b0c0431a21 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 @@ -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 { diff --git a/compiler/testData/cli/jvm/firErrorOnLastLine.args b/compiler/testData/cli/jvm/firErrorOnLastLine.args new file mode 100644 index 00000000000..f11f445097f --- /dev/null +++ b/compiler/testData/cli/jvm/firErrorOnLastLine.args @@ -0,0 +1,6 @@ +$TESTDATA_DIR$/firErrorOnLastLine.kt +-language-version +2.0 +-Xuse-fir-lt=true +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/firErrorOnLastLine.kt b/compiler/testData/cli/jvm/firErrorOnLastLine.kt new file mode 100644 index 00000000000..0cf7ff15d47 --- /dev/null +++ b/compiler/testData/cli/jvm/firErrorOnLastLine.kt @@ -0,0 +1,2 @@ +val x = this +val y = this // EOL AFTER THIS LINE! diff --git a/compiler/testData/cli/jvm/firErrorOnLastLine.out b/compiler/testData/cli/jvm/firErrorOnLastLine.out new file mode 100644 index 00000000000..dc481ef8bcb --- /dev/null +++ b/compiler/testData/cli/jvm/firErrorOnLastLine.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/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 diff --git a/compiler/testData/cli/jvm/firErrorOnLastLineNoEol.args b/compiler/testData/cli/jvm/firErrorOnLastLineNoEol.args new file mode 100644 index 00000000000..ba61d83e51f --- /dev/null +++ b/compiler/testData/cli/jvm/firErrorOnLastLineNoEol.args @@ -0,0 +1,6 @@ +$TESTDATA_DIR$/firErrorOnLastLineNoEol.kt +-language-version +2.0 +-Xuse-fir-lt=true +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/firErrorOnLastLineNoEol.kt b/compiler/testData/cli/jvm/firErrorOnLastLineNoEol.kt new file mode 100644 index 00000000000..07ba47ce283 --- /dev/null +++ b/compiler/testData/cli/jvm/firErrorOnLastLineNoEol.kt @@ -0,0 +1,2 @@ +val x = this +val y = this // *NO* EOL AFTER THIS LINE! \ No newline at end of file diff --git a/compiler/testData/cli/jvm/firErrorOnLastLineNoEol.out b/compiler/testData/cli/jvm/firErrorOnLastLineNoEol.out new file mode 100644 index 00000000000..6e1fee632c0 --- /dev/null +++ b/compiler/testData/cli/jvm/firErrorOnLastLineNoEol.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/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 diff --git a/compiler/testData/cli/jvm/firSyntaxError.args b/compiler/testData/cli/jvm/firSyntaxError.args new file mode 100644 index 00000000000..bc412aa6fb3 --- /dev/null +++ b/compiler/testData/cli/jvm/firSyntaxError.args @@ -0,0 +1,5 @@ +$TESTDATA_DIR$/firSyntaxError.kt +-language-version +2.0 +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/firSyntaxError.kt b/compiler/testData/cli/jvm/firSyntaxError.kt new file mode 100644 index 00000000000..618e427eb2b --- /dev/null +++ b/compiler/testData/cli/jvm/firSyntaxError.kt @@ -0,0 +1 @@ +fun a() { diff --git a/compiler/testData/cli/jvm/firSyntaxError.out b/compiler/testData/cli/jvm/firSyntaxError.out new file mode 100644 index 00000000000..e030b36e891 --- /dev/null +++ b/compiler/testData/cli/jvm/firSyntaxError.out @@ -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 diff --git a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java index 36e18688602..230aea26077 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -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");