diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-11-22 17:23:45 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-11-22 19:13:24 +0100 |
commit | 0c963c90855eb0811bc1b6c3ab35814ee0768f13 (patch) | |
tree | 74317fcd3dbd6de645289381cf9835309ef3e18e | |
parent | 2ad9666ce8863814dd5d27f1d43739e89c8c286b (diff) | |
download | scala-0c963c90855eb0811bc1b6c3ab35814ee0768f13.tar.gz scala-0c963c90855eb0811bc1b6c3ab35814ee0768f13.tar.bz2 scala-0c963c90855eb0811bc1b6c3ab35814ee0768f13.zip |
[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.
-rw-r--r-- | src/compiler/scala/tools/reflect/ToolBoxFactory.scala | 9 | ||||
-rw-r--r-- | test/files/run/toolbox_rangepos.check | 1 | ||||
-rw-r--r-- | test/files/run/toolbox_rangepos.scala | 8 |
3 files changed, 16 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala index b9541ece5d..8803980dac 100644 --- a/src/compiler/scala/tools/reflect/ToolBoxFactory.scala +++ b/src/compiler/scala/tools/reflect/ToolBoxFactory.scala @@ -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 diff --git a/test/files/run/toolbox_rangepos.check b/test/files/run/toolbox_rangepos.check new file mode 100644 index 0000000000..b536d3fde1 --- /dev/null +++ b/test/files/run/toolbox_rangepos.check @@ -0,0 +1 @@ +RangePosition(<toolbox>, 0, 2, 5) diff --git a/test/files/run/toolbox_rangepos.scala b/test/files/run/toolbox_rangepos.scala new file mode 100644 index 0000000000..41fe6daa03 --- /dev/null +++ b/test/files/run/toolbox_rangepos.scala @@ -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) +} |