Permalink
Browse files

Fix for SI-5385.

Nodes which hit EOF with no whitespace afterward had
wrong position.
  • Loading branch information...
paulp authored and hubertp committed Mar 11, 2012
1 parent 0cfd858 commit 32fd97df41bb2e99018f024f41b06490e41bd7ad
@@ -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")
@@ -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.##
}
@@ -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
@@ -12,5 +12,5 @@ t4069.scala:4: error: I encountered a '}' where I didn't expect one, maybe this
^
t4069.scala:10: error: '}' expected but eof found.
}
^
^
5 errors found
@@ -1,4 +1,7 @@
t4584.scala:1: error: incomplete unicode escape
t4584.scala:1: error: error in unicode escape
class A { val /u2
^
t4584.scala:1: error: illegal character '/uffff'
class A { val /u2
^
one error found
two errors found
@@ -1,4 +1,7 @@
unicode-unterminated-quote.scala:2: error: unclosed string literal
val x = /u0022
^
one error found
unicode-unterminated-quote.scala:2: error: '}' expected but eof found.
val x = /u0022
^
two errors found
@@ -0,0 +1,8 @@
[0:9] class Azz
[0:9] class Bzz
[0:9] class Czz
[0:9] class Dzz
[0:11] class Ezz
[0:11] class Fzz
[0:13] class Gzz
[0:13] class Hzz
View
@@ -0,0 +1,16 @@
import scala.tools.partest._
object Test extends CompilerTest {
import global._
override def extraSettings = super.extraSettings + " -Yrangepos"
override def sources = List(
"class Azz", "class Bzz ", "class Czz ", "class Dzz\n",
"class Ezz{}", "class Fzz{} ", "class Gzz { }", "class Hzz { } "
)
def check(source: String, unit: CompilationUnit) {
unit.body foreach {
case cdef: ClassDef => println("%-15s class %s".format(cdef.pos.show, cdef.name))
case _ =>
}
}
}

0 comments on commit 32fd97d

Please sign in to comment.