Skip to content

Commit 15fba6b

Browse files
author
Adriaan Moors
committed
Merge pull request scala#924 from hubertp/2.10.x-issue/5385
Fix for SI-5385.
2 parents b0742eb + 32fd97d commit 15fba6b

File tree

8 files changed

+55
-14
lines changed

8 files changed

+55
-14
lines changed

src/partest/scala/tools/partest/DirectTest.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ abstract class DirectTest extends App {
3838
// new compiler
3939
def newCompiler(args: String*): Global = {
4040
val settings = newSettings((CommandLineParser tokenize extraSettings) ++ args.toList)
41-
new Global(settings)
41+
if (settings.Yrangepos.value) new Global(settings) with interactive.RangePositions
42+
else new Global(settings)
4243
}
4344
def newSources(sourceCodes: String*) = sourceCodes.toList.zipWithIndex map {
4445
case (src, idx) => new BatchSourceFile("newSource" + (idx + 1), src)
@@ -69,7 +70,7 @@ abstract class DirectTest extends App {
6970

7071
/** Constructor/main body **/
7172
try show()
72-
catch { case t => println(t) ; t.printStackTrace ; sys.exit(1) }
73+
catch { case t => println(t.getMessage) ; t.printStackTrace ; sys.exit(1) }
7374

7475
/** Debugger interest only below this line **/
7576
protected def isDebug = (sys.props contains "partest.debug") || (sys.env contains "PARTEST_DEBUG")

src/reflect/scala/reflect/internal/util/SourceFile.scala

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/reflect/scala/tools/nsc/io/VirtualFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF
5555
}
5656
}
5757

58-
def container: AbstractFile = unsupported
58+
def container: AbstractFile = NoAbstractFile
5959

6060
/** Is this abstract file a directory? */
6161
def isDirectory: Boolean = false

test/files/neg/t4069.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ t4069.scala:4: error: I encountered a '}' where I didn't expect one, maybe this
1212
^
1313
t4069.scala:10: error: '}' expected but eof found.
1414
}
15-
^
15+
^
1616
5 errors found

test/files/neg/t4584.check

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
t4584.scala:1: error: incomplete unicode escape
1+
t4584.scala:1: error: error in unicode escape
2+
class A { val /u2
3+
^
4+
t4584.scala:1: error: illegal character '/uffff'
25
class A { val /u2
36
^
4-
one error found
7+
two errors found
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
unicode-unterminated-quote.scala:2: error: unclosed string literal
22
val x = /u0022
33
^
4-
one error found
4+
unicode-unterminated-quote.scala:2: error: '}' expected but eof found.
5+
val x = /u0022
6+
^
7+
two errors found

test/files/run/t5385.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[0:9] class Azz
2+
[0:9] class Bzz
3+
[0:9] class Czz
4+
[0:9] class Dzz
5+
[0:11] class Ezz
6+
[0:11] class Fzz
7+
[0:13] class Gzz
8+
[0:13] class Hzz

test/files/run/t5385.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import scala.tools.partest._
2+
3+
object Test extends CompilerTest {
4+
import global._
5+
override def extraSettings = super.extraSettings + " -Yrangepos"
6+
override def sources = List(
7+
"class Azz", "class Bzz ", "class Czz ", "class Dzz\n",
8+
"class Ezz{}", "class Fzz{} ", "class Gzz { }", "class Hzz { } "
9+
)
10+
def check(source: String, unit: CompilationUnit) {
11+
unit.body foreach {
12+
case cdef: ClassDef => println("%-15s class %s".format(cdef.pos.show, cdef.name))
13+
case _ =>
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)