From 9e3518cd893e796b555c4f78f79740ccfa3d4dbd Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 17 May 2017 14:38:42 +0200 Subject: [PATCH] Fix #2213: Fix errors positioned after EOF --- compiler/src/dotty/tools/dotc/util/SourceFile.scala | 3 ++- tests/repl/i2213.check | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/repl/i2213.check diff --git a/compiler/src/dotty/tools/dotc/util/SourceFile.scala b/compiler/src/dotty/tools/dotc/util/SourceFile.scala index 1d4c9c2ab6f2..1a17fb8ee445 100644 --- a/compiler/src/dotty/tools/dotc/util/SourceFile.scala +++ b/compiler/src/dotty/tools/dotc/util/SourceFile.scala @@ -107,6 +107,7 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) extends interfac */ def offsetToLine(offset: Int): Int = { lastLine = Util.bestFit(lineIndices, lineIndices.length, offset, lastLine) + if (offset >= length) lastLine -= 1 // compensate for the sentinel lastLine } @@ -129,7 +130,7 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) extends interfac var idx = startOfLine(offset) var col = 0 while (idx != offset) { - col += (if (content(idx) == '\t') (tabInc - col) % tabInc else 1) + col += (if (idx < length && content(idx) == '\t') (tabInc - col) % tabInc else 1) idx += 1 } col diff --git a/tests/repl/i2213.check b/tests/repl/i2213.check new file mode 100644 index 000000000000..40e9395143e8 --- /dev/null +++ b/tests/repl/i2213.check @@ -0,0 +1,8 @@ +scala> def x +-- [E018] Syntax Error: :1:5 ------------------------------------------ +1 |def x + | ^ + | missing return type + +longer explanation available when compiling with `-explain` +scala> :quit