Skip to content

Commit 8541396

Browse files
author
Tobias Bordenca
committed
Proper fix for settings color in QuotedDriver
1 parent aa9516d commit 8541396

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools.dotc.quoted
22

33
import dotty.tools.dotc.ast.tpd
44
import dotty.tools.dotc.Driver
5-
import dotty.tools.dotc.core.Contexts.{Context, ContextBase}
5+
import dotty.tools.dotc.core.Contexts.{Context, ContextBase, FreshContext}
66
import dotty.tools.dotc.tastyreflect.TastyImpl
77
import dotty.tools.io.{AbstractFile, Directory, PlainDirectory, VirtualDirectory}
88
import dotty.tools.repl.AbstractFileClassLoader
@@ -27,7 +27,7 @@ class QuoteDriver extends Driver {
2727
}
2828

2929
val (_, ctx0: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)
30-
val ctx = ctx0.fresh.setSetting(ctx0.settings.outputDir, outDir)
30+
val ctx = setColor(ctx0.fresh.setSetting(ctx0.settings.outputDir, outDir), settings)
3131

3232
val driver = new QuoteCompiler
3333
driver.newRun(ctx).compileExpr(expr)
@@ -50,7 +50,7 @@ class QuoteDriver extends Driver {
5050
}
5151

5252
def withTree[T](expr: Expr[_], f: (Tree, Context) => T, settings: Toolbox.Settings): T = {
53-
val (_, ctx: Context) = setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)
53+
val ctx = setColor(setup(settings.compilerArgs.toArray :+ "dummy.scala", initCtx.fresh)._2.fresh, settings)
5454

5555
var output: Option[T] = None
5656
def registerTree(tree: tpd.Tree)(ctx: Context): Unit = {
@@ -79,6 +79,9 @@ class QuoteDriver extends Driver {
7979
ictx
8080
}
8181

82+
private def setColor(ctx: FreshContext, settings: Toolbox.Settings): FreshContext =
83+
ctx.setSetting(ctx.settings.color, if (settings.color) "always" else "never")
84+
8285
}
8386

8487
object QuoteDriver {

library/src/scala/quoted/Toolbox.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object Toolbox {
3232
}
3333

3434
/** Setting of the Toolbox instance. */
35-
class Settings private (val outDir: Option[String], val showRawTree: Boolean, val compilerArgs: List[String])
35+
class Settings private (val outDir: Option[String], val showRawTree: Boolean, val compilerArgs: List[String], val color: Boolean)
3636

3737
object Settings {
3838

@@ -49,10 +49,8 @@ object Toolbox {
4949
showRawTree: Boolean = false,
5050
outDir: Option[String] = None,
5151
compilerArgs: List[String] = Nil
52-
): Settings = {
53-
val colorArg = if (color) "-color:always" else "-color:never"
54-
new Settings(outDir, showRawTree, colorArg :: compilerArgs)
55-
}
52+
): Settings =
53+
new Settings(outDir, showRawTree, compilerArgs, color)
5654
}
5755

5856
class ToolboxNotFoundException(msg: String, cause: ClassNotFoundException) extends Exception(msg, cause)

0 commit comments

Comments
 (0)