Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

SI-8015 Unprintables in messages

The line content to display should include the whole line,
inclusive of embedded line breaks, and any control chars
should be displayed in unicode escape.
  • Loading branch information...
commit 8be560a1cf6306ea4ed2596f3b6631c2e44d8213 1 parent bb2e99a
som-snytt som-snytt authored
11 src/reflect/scala/reflect/internal/util/Position.scala
View
@@ -207,7 +207,16 @@ private[util] trait InternalPositionImpl {
def showError(msg: String): String = finalPosition match {
case FakePos(fmsg) => s"$fmsg $msg"
case NoPosition => msg
- case pos => s"${pos.line}: $msg\n${pos.lineContent}\n${pos.lineCarat}"
+ case pos => f"${pos.line}: $msg%n${u(pos.lineContent)}%n${pos.lineCarat}"
+ }
+ private def u(s: String) = {
+ def uu(c: Int) = f"\\u$c%04x"
+ def uable(c: Int) = (c < 0x20 && c != '\t') || c == 0x7F
+ if (s exists (c => uable(c))) {
+ val sb = new StringBuilder
+ s foreach (c => sb append (if (uable(c)) uu(c) else c))
+ sb.toString
+ } else s
}
def showDebug: String = toString
def show = (
8 src/reflect/scala/reflect/internal/util/SourceFile.scala
View
@@ -37,8 +37,12 @@ abstract class SourceFile {
override def toString() = file.name
def path = file.path
- def lineToString(index: Int): String =
- content drop lineToOffset(index) takeWhile (c => !isLineBreakChar(c.toChar)) mkString ""
+ def lineToString(index: Int): String = {
+ val start = lineToOffset(index)
+ var end = start
+ while (!isEndOfLine(end)) end += 1
+ content.slice(start, end) mkString ""
+ }
@tailrec
final def skipWhitespace(offset: Int): Int =
2  test/files/neg/t8015-ffb.check
View
@@ -1,5 +1,5 @@
t8015-ffb.scala:10: warning: side-effecting nullary methods are discouraged: suggest defining as `def w()` instead
- def w = { x
+ def w = { x\u000c() } // ^L is colored blue on this screen, hardly visible
^
error: No warnings can be incurred under -Xfatal-warnings.
one warning found
Please sign in to comment.
Something went wrong with that request. Please try again.