diff options
-rw-r--r-- | src/compiler/scala/reflect/runtime/ToolBoxes.scala | 8 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/CompilerCommand.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Settings.scala | 6 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/settings/MutableSettings.scala | 17 | ||||
-rw-r--r-- | test/files/run/t5239.check | 13 | ||||
-rw-r--r-- | test/files/run/t5239.scala | 20 |
6 files changed, 65 insertions, 1 deletions
diff --git a/src/compiler/scala/reflect/runtime/ToolBoxes.scala b/src/compiler/scala/reflect/runtime/ToolBoxes.scala index 7ec7d15fb7..e617239398 100644 --- a/src/compiler/scala/reflect/runtime/ToolBoxes.scala +++ b/src/compiler/scala/reflect/runtime/ToolBoxes.scala @@ -3,6 +3,7 @@ package runtime import scala.tools.nsc.reporters.Reporter import scala.tools.nsc.reporters.StoreReporter +import scala.tools.nsc.reporters.AbstractReporter import scala.tools.nsc.ReflectGlobal import scala.tools.nsc.CompilerCommand import scala.tools.nsc.Global @@ -109,7 +110,12 @@ trait ToolBoxes extends { self: Universe => } lazy val compiler: ToolBoxGlobal = { - val command = new CompilerCommand(arguments.toList, reporter.error(scala.tools.nsc.util.NoPosition, _)) + val errorFn: String => Unit = reporter.error(scala.tools.nsc.util.NoPosition, _) + val command = reporter match { + case reporter: AbstractReporter => new CompilerCommand(arguments.toList, reporter.settings, errorFn) + case _ => new CompilerCommand(arguments.toList, errorFn) + } + command.settings.outputDirs setSingleOutput virtualDirectory new ToolBoxGlobal(command.settings, reporter) } diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index 63cb62ee2e..54bc218912 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -11,6 +11,8 @@ import io.File /** A class representing command line info for scalac */ class CompilerCommand(arguments: List[String], val settings: Settings) { def this(arguments: List[String], error: String => Unit) = this(arguments, new Settings(error)) + def this(arguments: List[String], settings: Settings, error: String => Unit) = this(arguments, settings withErrorFn error) + type Setting = Settings#Setting /** file extensions of files that the compiler can process */ diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index ca99ddf27a..d57d5546fa 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -11,4 +11,10 @@ import settings.MutableSettings */ class Settings(errorFn: String => Unit) extends MutableSettings(errorFn) { def this() = this(Console.println) + + override def withErrorFn(errorFn: String => Unit): Settings = { + val settings = new Settings(errorFn) + copyInto(settings) + settings + } } diff --git a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala index 67a556f6f0..b468e7c0af 100644 --- a/src/compiler/scala/tools/nsc/settings/MutableSettings.scala +++ b/src/compiler/scala/tools/nsc/settings/MutableSettings.scala @@ -22,6 +22,23 @@ class MutableSettings(val errorFn: String => Unit) with Mutable { type ResultOfTryToSet = List[String] + def withErrorFn(errorFn: String => Unit): MutableSettings = { + val settings = new MutableSettings(errorFn) + copyInto(settings) + settings + } + + protected def copyInto(settings: MutableSettings) { + allSettings foreach { thisSetting => + val otherSetting = settings.allSettings find { _.name == thisSetting.name } + otherSetting foreach { otherSetting => + if (thisSetting.isSetByUser || otherSetting.isSetByUser) { + otherSetting.value = thisSetting.value.asInstanceOf[otherSetting.T] + } + } + } + } + /** Iterates over the arguments applying them to settings where applicable. * Then verifies setting dependencies are met. * diff --git a/test/files/run/t5239.check b/test/files/run/t5239.check new file mode 100644 index 0000000000..db5778f95b --- /dev/null +++ b/test/files/run/t5239.check @@ -0,0 +1,13 @@ +result = 2{Int(2)} +[[syntax trees at end of typer]]// Scala source: NoSourceFile +package <empty> { + final object __wrapper$1 extends Object { + def this(): object __wrapper$1 = { + __wrapper$1.super.this(); + () + }; + <static> def wrapper(): Int = 2 + } +} + +evaluated = 2 diff --git a/test/files/run/t5239.scala b/test/files/run/t5239.scala new file mode 100644 index 0000000000..1f404196ba --- /dev/null +++ b/test/files/run/t5239.scala @@ -0,0 +1,20 @@ +import scala.tools.nsc.reporters._ +import scala.tools.nsc.Settings +import reflect.runtime.Mirror.ToolBox + +object Test extends App { + val code = scala.reflect.Code.lift{ + 2 + }; + + val settings = new Settings + settings.Xprint.value = List("typer") + + val reporter = new ConsoleReporter(settings) + val toolbox = new ToolBox(reporter) + val ttree = toolbox.typeCheck(code.tree) + println("result = " + toolbox.showAttributed(ttree)) + + val evaluated = toolbox.runExpr(ttree) + println("evaluated = " + evaluated) +} |