Skip to content

Commit c38a6b7

Browse files
Merge pull request #4462 from dotty-staging/fix-3932
Fix #3932: ANSI color leak in repl
2 parents 83735d2 + da0b6ba commit c38a6b7

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
169169
"<noprefix>"
170170
case tp: MethodType =>
171171
changePrec(GlobalPrec) {
172-
(if (tp.isImplicitMethod) "(implicit " else "(") ~ paramsText(tp) ~
172+
("(" + (if (tp.isErasedMethod) "erased " else "")
173+
+ (if (tp.isImplicitMethod) "implicit " else "")
174+
) ~ paramsText(tp) ~
173175
(if (tp.resultType.isInstanceOf[MethodType]) ")" else "): ") ~
174176
toText(tp.resultType)
175177
}
@@ -536,9 +538,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
536538
protected def literalText(text: Text): Text = coloredText(text, SyntaxHighlighting.LiteralColor)
537539
protected def stringText(text: Text): Text = coloredText(text, SyntaxHighlighting.StringColor)
538540

539-
private def coloredStr(text: String, color: String): String =
541+
protected def coloredStr(text: String, color: String): String =
540542
if (ctx.useColors) color + text + SyntaxHighlighting.NoColor else text
541-
private def coloredText(text: Text, color: String): Text =
543+
protected def coloredText(text: Text, color: String): Text =
542544
if (ctx.useColors) color ~ text ~ SyntaxHighlighting.NoColor else text
543545
}
544546

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/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object SyntaxHighlighting {
3131
private val tripleQs = Console.RED_B + "???" + NoColor
3232

3333
private val keywords: Seq[String] = for {
34-
index <- IF to ENUM // All alpha keywords
34+
index <- IF to ERASED // All alpha keywords
3535
} yield tokenString(index)
3636

3737
private val interpolationPrefixes =

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

compiler/test-resources/repl/erased

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scala> def f(erased a: Int): Int = ???
2+
def f(erased a: Int): Int
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
scala> def f(erased implicit a: Int): Int = ???
2+
def f(erased implicit a: Int): Int

0 commit comments

Comments
 (0)