From 0c963c90855eb0811bc1b6c3ab35814ee0768f13 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Fri, 22 Nov 2013 17:23:45 +0100 Subject: [nomaster] teaches toolbox about -Yrangepos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/compiler/scala/tools/reflect/ToolBoxFactory.scala | 9 +++++++-- test/files/run/toolbox_rangepos.check | 1 + test/files/run/toolbox_rangepos.scala | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/files/run/toolbox_rangepos.check create mode 100644 test/files/run/toolbox_rangepos.scala 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(, 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) +} -- cgit v1.2.3