summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-03-11 00:14:16 -0500
committerHubert Plociniczak <hubert.plociniczak@gmail.com>2012-07-17 12:04:38 +0200
commit32fd97df41bb2e99018f024f41b06490e41bd7ad (patch)
tree4b40fb915776892da3de3227f771a205a2c38a82 /src
parent0cfd858a38ddf0ac83d9bbefe85110f88dc707c0 (diff)
downloadscala-32fd97df41bb2e99018f024f41b06490e41bd7ad.tar.gz
scala-32fd97df41bb2e99018f024f41b06490e41bd7ad.tar.bz2
scala-32fd97df41bb2e99018f024f41b06490e41bd7ad.zip
Fix for SI-5385.
Nodes which hit EOF with no whitespace afterward had wrong position.
Diffstat (limited to 'src')
-rw-r--r--src/partest/scala/tools/partest/DirectTest.scala5
-rw-r--r--src/reflect/scala/reflect/internal/util/SourceFile.scala24
-rw-r--r--src/reflect/scala/tools/nsc/io/VirtualFile.scala2
3 files changed, 21 insertions, 10 deletions
diff --git a/src/partest/scala/tools/partest/DirectTest.scala b/src/partest/scala/tools/partest/DirectTest.scala
index 4e7f36bdc9..5b4e1b4b25 100644
--- a/src/partest/scala/tools/partest/DirectTest.scala
+++ b/src/partest/scala/tools/partest/DirectTest.scala
@@ -38,7 +38,8 @@ abstract class DirectTest extends App {
// new compiler
def newCompiler(args: String*): Global = {
val settings = newSettings((CommandLineParser tokenize extraSettings) ++ args.toList)
- new Global(settings)
+ if (settings.Yrangepos.value) new Global(settings) with interactive.RangePositions
+ else new Global(settings)
}
def newSources(sourceCodes: String*) = sourceCodes.toList.zipWithIndex map {
case (src, idx) => new BatchSourceFile("newSource" + (idx + 1), src)
@@ -69,7 +70,7 @@ abstract class DirectTest extends App {
/** Constructor/main body **/
try show()
- catch { case t => println(t) ; t.printStackTrace ; sys.exit(1) }
+ catch { case t => println(t.getMessage) ; t.printStackTrace ; sys.exit(1) }
/** Debugger interest only below this line **/
protected def isDebug = (sys.props contains "partest.debug") || (sys.env contains "PARTEST_DEBUG")
diff --git a/src/reflect/scala/reflect/internal/util/SourceFile.scala b/src/reflect/scala/reflect/internal/util/SourceFile.scala
index 7c80ddd37d..df4a3336c3 100644
--- a/src/reflect/scala/reflect/internal/util/SourceFile.scala
+++ b/src/reflect/scala/reflect/internal/util/SourceFile.scala
@@ -102,17 +102,21 @@ class ScriptSourceFile(underlying: BatchSourceFile, content: Array[Char], overri
}
/** a file whose contents do not change over time */
-class BatchSourceFile(val file : AbstractFile, val content: Array[Char]) extends SourceFile {
-
+class BatchSourceFile(val file : AbstractFile, val content0: Array[Char]) extends SourceFile {
def this(_file: AbstractFile) = this(_file, _file.toCharArray)
def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray)
def this(file: AbstractFile, cs: Seq[Char]) = this(file, cs.toArray)
- override def equals(that : Any) = that match {
- case that : BatchSourceFile => file.path == that.file.path && start == that.start
- case _ => false
- }
- override def hashCode = file.path.## + start.##
+ // If non-whitespace tokens run all the way up to EOF,
+ // positions go wrong because the correct end of the last
+ // token cannot be used as an index into the char array.
+ // The least painful way to address this was to add a
+ // newline to the array.
+ val content = (
+ if (content0.length == 0 || !content0.last.isWhitespace)
+ content0 :+ '\n'
+ else content0
+ )
val length = content.length
def start = 0
def isSelfContained = true
@@ -158,4 +162,10 @@ class BatchSourceFile(val file : AbstractFile, val content: Array[Char]) extends
lastLine = findLine(0, lines.length, lastLine)
lastLine
}
+
+ override def equals(that : Any) = that match {
+ case that : BatchSourceFile => file.path == that.file.path && start == that.start
+ case _ => false
+ }
+ override def hashCode = file.path.## + start.##
}
diff --git a/src/reflect/scala/tools/nsc/io/VirtualFile.scala b/src/reflect/scala/tools/nsc/io/VirtualFile.scala
index b9a946598c..805bc04165 100644
--- a/src/reflect/scala/tools/nsc/io/VirtualFile.scala
+++ b/src/reflect/scala/tools/nsc/io/VirtualFile.scala
@@ -55,7 +55,7 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF
}
}
- def container: AbstractFile = unsupported
+ def container: AbstractFile = NoAbstractFile
/** Is this abstract file a directory? */
def isDirectory: Boolean = false