Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[nomaster] teaches toolbox about -Yrangepos

Unlike in master, in 2.10.x enabling -Yrangepos requires instantiating
Global with mixed in RangePositions trait.

Same story for toolboxes. Just setting Yrangepos is not enough - one
needs to mix in RangePositions into ToolboxGlobal. I didn’t know that
back then, so now I’m fixing the oversight.

The commit is marked as [nomaster], because -Yrangepos doesn’t need
special treatment in master.
  • Loading branch information...
commit 0c963c90855eb0811bc1b6c3ab35814ee0768f13 1 parent 2ad9666
Eugene Burmako xeno-by authored
9 src/compiler/scala/tools/reflect/ToolBoxFactory.scala
View
@@ -16,6 +16,7 @@ import scala.compat.Platform.EOL
import scala.reflect.NameTransformer
import scala.reflect.api.JavaUniverse
import scala.reflect.io.NoAbstractFile
+import scala.tools.nsc.interactive.RangePositions
abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
@@ -329,8 +330,12 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
try {
val errorFn: String => Unit = msg => frontEnd.log(scala.reflect.internal.util.NoPosition, msg, frontEnd.ERROR)
val command = new CompilerCommand(arguments.toList, errorFn)
- command.settings.outputDirs setSingleOutput virtualDirectory
- val instance = new ToolBoxGlobal(command.settings, frontEndToReporter(frontEnd, command.settings))
+ val settings = command.settings
+ settings.outputDirs setSingleOutput virtualDirectory
+ val reporter = frontEndToReporter(frontEnd, command.settings)
+ val instance =
+ if (settings.Yrangepos.value) new ToolBoxGlobal(settings, reporter) with RangePositions
+ else new ToolBoxGlobal(settings, reporter)
if (frontEnd.hasErrors) {
var msg = "reflective compilation has failed: cannot initialize the compiler: " + EOL + EOL
msg += frontEnd.infos map (_.msg) mkString EOL
1  test/files/run/toolbox_rangepos.check
View
@@ -0,0 +1 @@
+RangePosition(<toolbox>, 0, 2, 5)
8 test/files/run/toolbox_rangepos.scala
View
@@ -0,0 +1,8 @@
+import scala.reflect.runtime.{currentMirror => cm}
+import scala.tools.reflect.ToolBox
+
+object Test extends App {
+ val toolbox = cm.mkToolBox(options = "-Yrangepos")
+ val tree = toolbox.parse("2 + 2")
+ println(tree.pos)
+}
Please sign in to comment.
Something went wrong with that request. Please try again.