aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-06-25 12:01:32 +0200
committerMartin Odersky <odersky@gmail.com>2015-06-25 12:02:32 +0200
commitd00572d159a3a15664afbf09d1ff914df4d2c512 (patch)
treeb707a4f0cc70f68819101ae7e428cc6a79d3ba8e /src
parent0fba8757b444d96c748df1e034d39f7626a39d1e (diff)
downloaddotty-d00572d159a3a15664afbf09d1ff914df4d2c512.tar.gz
dotty-d00572d159a3a15664afbf09d1ff914df4d2c512.tar.bz2
dotty-d00572d159a3a15664afbf09d1ff914df4d2c512.zip
Avoid crasher when first token of a program is in error
This used to give a crash in SourcePositiom, promoted by feeding its calculations with a negative offset.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala2
-rw-r--r--src/dotty/tools/dotc/util/SourceFile.scala5
2 files changed, 5 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala
index b79077245..2a42a7fa9 100644
--- a/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -192,7 +192,7 @@ object Parsers {
case _ =>
if (mustStartStat &&
in.isAfterLineEnd() &&
- isLeqIndented(in.offset, lastStatOffset))
+ isLeqIndented(in.offset, lastStatOffset max 0))
return
}
in.nextToken()
diff --git a/src/dotty/tools/dotc/util/SourceFile.scala b/src/dotty/tools/dotc/util/SourceFile.scala
index 45119a881..6e2ac7d79 100644
--- a/src/dotty/tools/dotc/util/SourceFile.scala
+++ b/src/dotty/tools/dotc/util/SourceFile.scala
@@ -103,7 +103,10 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
lastLine
}
- def startOfLine(offset: Int): Int = lineToOffset(offsetToLine(offset))
+ def startOfLine(offset: Int): Int = {
+ require(offset >= 0)
+ lineToOffset(offsetToLine(offset))
+ }
def nextLine(offset: Int): Int =
lineToOffset(offsetToLine(offset) + 1 min lineIndices.length - 1)