diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-06-03 13:17:35 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-06-03 13:17:35 +0200 |
commit | f0daf47f7d983ca7b429b7c386d270c41d2889f4 (patch) | |
tree | d25badd98d1bf4645c8c0c85ee79170088db5e1f | |
parent | 1b280b32199dec573b9c1a7f3bd8f354c01e86c5 (diff) | |
parent | 5277fb4d69714b52a9c43fd6ac439e6d16d7a3e9 (diff) | |
download | scala-f0daf47f7d983ca7b429b7c386d270c41d2889f4.tar.gz scala-f0daf47f7d983ca7b429b7c386d270c41d2889f4.tar.bz2 scala-f0daf47f7d983ca7b429b7c386d270c41d2889f4.zip |
Merge pull request #3796 from som-snytt/issue/8630
SI-8630 lineToString no longer long by one at eof
-rw-r--r-- | src/reflect/scala/reflect/internal/util/SourceFile.scala | 2 | ||||
-rw-r--r-- | test/files/neg/t8630.check | 7 | ||||
-rw-r--r-- | test/files/neg/t8630.scala | 1 | ||||
-rw-r--r-- | test/junit/scala/reflect/internal/util/SourceFileTest.scala | 5 |
4 files changed, 14 insertions, 1 deletions
diff --git a/src/reflect/scala/reflect/internal/util/SourceFile.scala b/src/reflect/scala/reflect/internal/util/SourceFile.scala index 4fccad74ac..a2642628a4 100644 --- a/src/reflect/scala/reflect/internal/util/SourceFile.scala +++ b/src/reflect/scala/reflect/internal/util/SourceFile.scala @@ -40,7 +40,7 @@ abstract class SourceFile { def lineToString(index: Int): String = { val start = lineToOffset(index) var end = start - while (!isEndOfLine(end) && end <= length) end += 1 + while (end < length && !isEndOfLine(end)) end += 1 new String(content, start, end - start) } diff --git a/test/files/neg/t8630.check b/test/files/neg/t8630.check new file mode 100644 index 0000000000..98b084b153 --- /dev/null +++ b/test/files/neg/t8630.check @@ -0,0 +1,7 @@ +t8630.scala:1: error: '{' expected but 'abstract' found. +package bobsdelights abstract class Fruit( val name: String, val color: String ) object Fruits { object Apple extends Fruit("apple", "red") object Orange extends Fruit("orange", "orange") object Pear extends Fruit("pear", "yellowish") val menu = List(Apple, Orange, Pear) } + ^ +t8630.scala:1: error: '}' expected but eof found. +package bobsdelights abstract class Fruit( val name: String, val color: String ) object Fruits { object Apple extends Fruit("apple", "red") object Orange extends Fruit("orange", "orange") object Pear extends Fruit("pear", "yellowish") val menu = List(Apple, Orange, Pear) } + ^ +two errors found diff --git a/test/files/neg/t8630.scala b/test/files/neg/t8630.scala new file mode 100644 index 0000000000..ea25227452 --- /dev/null +++ b/test/files/neg/t8630.scala @@ -0,0 +1 @@ +package bobsdelights abstract class Fruit( val name: String, val color: String ) object Fruits { object Apple extends Fruit("apple", "red") object Orange extends Fruit("orange", "orange") object Pear extends Fruit("pear", "yellowish") val menu = List(Apple, Orange, Pear) }
\ No newline at end of file diff --git a/test/junit/scala/reflect/internal/util/SourceFileTest.scala b/test/junit/scala/reflect/internal/util/SourceFileTest.scala index 903e705ba2..cad23eba14 100644 --- a/test/junit/scala/reflect/internal/util/SourceFileTest.scala +++ b/test/junit/scala/reflect/internal/util/SourceFileTest.scala @@ -17,6 +17,11 @@ class SourceFileTest { assertFalse(file.isEndOfLine(Int.MaxValue)) } + @Test def si8630_lineToString(): Unit = { + val code = "abc " + assertEquals(code, new BatchSourceFile("", code).lineToString(0)) + } + @Test def si8205_lineToString(): Unit = { assertEquals("", lineContentOf("", 0)) |