Skip to content

Fix #3932: ANSI color leak in repl #4462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case for erased implicit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

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