Skip to content

Commit

Permalink
Merge pull request scala#4462 from dotty-staging/fix-3932
Browse files Browse the repository at this point in the history
Fix scala#3932: ANSI color leak in repl
  • Loading branch information
OlivierBlanvillain authored May 12, 2018
2 parents 83735d2 + da0b6ba commit c38a6b7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
"<noprefix>"
case tp: MethodType =>
changePrec(GlobalPrec) {
(if (tp.isImplicitMethod) "(implicit " else "(") ~ paramsText(tp) ~
("(" + (if (tp.isErasedMethod) "erased " else "")
+ (if (tp.isImplicitMethod) "implicit " else "")
) ~ paramsText(tp) ~
(if (tp.resultType.isInstanceOf[MethodType]) ")" else "): ") ~
toText(tp.resultType)
}
Expand Down Expand Up @@ -536,9 +538,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
protected def literalText(text: Text): Text = coloredText(text, SyntaxHighlighting.LiteralColor)
protected def stringText(text: Text): Text = coloredText(text, SyntaxHighlighting.StringColor)

private def coloredStr(text: String, color: String): String =
protected def coloredStr(text: String, color: String): String =
if (ctx.useColors) color + text + SyntaxHighlighting.NoColor else text
private def coloredText(text: Text, color: String): Text =
protected def coloredText(text: Text, color: String): Text =
if (ctx.useColors) color ~ text ~ SyntaxHighlighting.NoColor else text
}

5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/ReplPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ class ReplPrinter(_ctx: Context) extends DecompilerPrinter(_ctx) {
else ":" ~~ toText(sym.info)
}
}

// We don't want the colors coming from RefinedPrinter as the REPL uses its
// own syntax coloring mechanism.
override def coloredStr(text: String, color: String): String = text
override def coloredText(text: Text, color: String): Text = text
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object SyntaxHighlighting {
private val tripleQs = Console.RED_B + "???" + NoColor

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

private val interpolationPrefixes =
Expand Down
2 changes: 2 additions & 0 deletions compiler/test-resources/repl/3932
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scala> def fun[T](x: T): implicit List[T] => Int = ???
def fun[T](x: T): implicit List[T] => Int
2 changes: 2 additions & 0 deletions compiler/test-resources/repl/erased
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scala> def f(erased a: Int): Int = ???
def f(erased a: Int): Int
2 changes: 2 additions & 0 deletions compiler/test-resources/repl/erased-implicit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scala> def f(erased implicit a: Int): Int = ???
def f(erased implicit a: Int): Int

0 comments on commit c38a6b7

Please sign in to comment.