From cfdb14d627d19dcdf32b2e6e80f4df9906eb385c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 28 Jul 2021 15:15:39 +0200 Subject: [PATCH] Remove color from scala.compiletime.codeOf We printed by mistake in color when the color flag was set. This was an unintetional change that happend when intinifying this operation. Fixes #13181 --- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 3 ++- compiler/test-resources/repl/i13181 | 2 ++ tests/run/i13181.scala | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 compiler/test-resources/repl/i13181 create mode 100644 tests/run/i13181.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 2068b9102899..cab9f397d507 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -379,7 +379,8 @@ object Inliner { /** Expand call to scala.compiletime.codeOf */ def codeOf(arg: Tree, pos: SrcPos)(using Context): Tree = - Literal(Constant(arg.show)).withSpan(pos.span) + val ctx1 = ctx.fresh.setSetting(ctx.settings.color, "never") + Literal(Constant(arg.show(using ctx1))).withSpan(pos.span) } extension (tp: Type) { diff --git a/compiler/test-resources/repl/i13181 b/compiler/test-resources/repl/i13181 new file mode 100644 index 000000000000..32f6c6e40c1e --- /dev/null +++ b/compiler/test-resources/repl/i13181 @@ -0,0 +1,2 @@ +scala> scala.compiletime.codeOf(1+2) +val res0: String = 1.+(2) diff --git a/tests/run/i13181.scala b/tests/run/i13181.scala new file mode 100644 index 000000000000..a6693b3f68e4 --- /dev/null +++ b/tests/run/i13181.scala @@ -0,0 +1 @@ +@main def Test = assert(scala.compiletime.codeOf(1+2) == "1.+(2)")