@@ -102,17 +102,21 @@ class ScriptSourceFile(underlying: BatchSourceFile, content: Array[Char], overri
102102}
103103
104104/** a file whose contents do not change over time */
105- class BatchSourceFile (val file : AbstractFile , val content : Array [Char ]) extends SourceFile {
106-
105+ class BatchSourceFile (val file : AbstractFile , val content0 : Array [Char ]) extends SourceFile {
107106 def this (_file : AbstractFile ) = this (_file, _file.toCharArray)
108107 def this (sourceName : String , cs : Seq [Char ]) = this (new VirtualFile (sourceName), cs.toArray)
109108 def this (file : AbstractFile , cs : Seq [Char ]) = this (file, cs.toArray)
110109
111- override def equals (that : Any ) = that match {
112- case that : BatchSourceFile => file.path == that.file.path && start == that.start
113- case _ => false
114- }
115- override def hashCode = file.path.## + start.##
110+ // If non-whitespace tokens run all the way up to EOF,
111+ // positions go wrong because the correct end of the last
112+ // token cannot be used as an index into the char array.
113+ // The least painful way to address this was to add a
114+ // newline to the array.
115+ val content = (
116+ if (content0.length == 0 || ! content0.last.isWhitespace)
117+ content0 :+ '\n '
118+ else content0
119+ )
116120 val length = content.length
117121 def start = 0
118122 def isSelfContained = true
@@ -158,4 +162,10 @@ class BatchSourceFile(val file : AbstractFile, val content: Array[Char]) extends
158162 lastLine = findLine(0 , lines.length, lastLine)
159163 lastLine
160164 }
165+
166+ override def equals (that : Any ) = that match {
167+ case that : BatchSourceFile => file.path == that.file.path && start == that.start
168+ case _ => false
169+ }
170+ override def hashCode = file.path.## + start.##
161171}
0 commit comments