Skip to content

Commit 7e9f3e7

Browse files
Fix #3932: prevent RefinedPrinter colors leaks
1 parent 80764e0 commit 7e9f3e7

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
536536
protected def literalText(text: Text): Text = coloredText(text, SyntaxHighlighting.LiteralColor)
537537
protected def stringText(text: Text): Text = coloredText(text, SyntaxHighlighting.StringColor)
538538

539-
private def coloredStr(text: String, color: String): String =
539+
protected def coloredStr(text: String, color: String): String =
540540
if (ctx.useColors) color + text + SyntaxHighlighting.NoColor else text
541-
private def coloredText(text: Text, color: String): Text =
541+
protected def coloredText(text: Text, color: String): Text =
542542
if (ctx.useColors) color ~ text ~ SyntaxHighlighting.NoColor else text
543543
}
544544

compiler/src/dotty/tools/dotc/printing/ReplPrinter.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ class ReplPrinter(_ctx: Context) extends DecompilerPrinter(_ctx) {
3737
else ":" ~~ toText(sym.info)
3838
}
3939
}
40+
41+
// We don't want the colors coming from RefinedPrinter as the REPL uses its
42+
// own syntax coloring mechanism.
43+
override def coloredStr(text: String, color: String): String = text
44+
override def coloredText(text: Text, color: String): Text = text
4045
}

compiler/test-resources/repl/3932

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scala> def fun[T](x: T): implicit List[T] => Int = ???
2+
def fun[T](x: T): implicit List[T] => Int

0 commit comments

Comments
 (0)