From bb2e99a69201060b88dd25602def42f31ba9ab65 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Tue, 17 Dec 2013 20:26:50 -0800 Subject: SI-8015 Count lines by EOLs Source lines were counted by "line break chars", including FF. Clients of `pos.line` seem to all expect the ordinary line num, so that is what they get. Unicode processing now precedes line ending processing. --- test/files/neg/t8015-ffa.check | 6 ++++++ test/files/neg/t8015-ffa.scala | 8 ++++++++ test/files/neg/t8015-ffb.check | 6 ++++++ test/files/neg/t8015-ffb.flags | 1 + test/files/neg/t8015-ffb.scala | 11 +++++++++++ test/files/run/t8015-ffc.scala | 7 +++++++ 6 files changed, 39 insertions(+) create mode 100644 test/files/neg/t8015-ffa.check create mode 100644 test/files/neg/t8015-ffa.scala create mode 100644 test/files/neg/t8015-ffb.check create mode 100644 test/files/neg/t8015-ffb.flags create mode 100644 test/files/neg/t8015-ffb.scala create mode 100644 test/files/run/t8015-ffc.scala (limited to 'test/files') diff --git a/test/files/neg/t8015-ffa.check b/test/files/neg/t8015-ffa.check new file mode 100644 index 0000000000..0f28be7fe7 --- /dev/null +++ b/test/files/neg/t8015-ffa.check @@ -0,0 +1,6 @@ +t8015-ffa.scala:7: error: type mismatch; + found : String("3") + required: Int + val i: Int = "3" // error line 7 (was 8) + ^ +one error found diff --git a/test/files/neg/t8015-ffa.scala b/test/files/neg/t8015-ffa.scala new file mode 100644 index 0000000000..60876d9139 --- /dev/null +++ b/test/files/neg/t8015-ffa.scala @@ -0,0 +1,8 @@ + +package foo + +//------- object Next + +trait F { + val i: Int = "3" // error line 7 (was 8) +} diff --git a/test/files/neg/t8015-ffb.check b/test/files/neg/t8015-ffb.check new file mode 100644 index 0000000000..90c8d045b4 --- /dev/null +++ b/test/files/neg/t8015-ffb.check @@ -0,0 +1,6 @@ +t8015-ffb.scala:10: warning: side-effecting nullary methods are discouraged: suggest defining as `def w()` instead + def w = { x + ^ +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found diff --git a/test/files/neg/t8015-ffb.flags b/test/files/neg/t8015-ffb.flags new file mode 100644 index 0000000000..7949c2afa2 --- /dev/null +++ b/test/files/neg/t8015-ffb.flags @@ -0,0 +1 @@ +-Xlint -Xfatal-warnings diff --git a/test/files/neg/t8015-ffb.scala b/test/files/neg/t8015-ffb.scala new file mode 100644 index 0000000000..dbdd942555 --- /dev/null +++ b/test/files/neg/t8015-ffb.scala @@ -0,0 +1,11 @@ + +trait G { + val c: Char = '\u000a' // disallowed! + def x\u000d\u000a = 9 // as nl + def y() = x + def z() = { + y()\u000a() // was Int does not take parameters + } + def v = y()\u000c() // was Int does not take parameters + def w = { x () } // ^L is colored blue on this screen, hardly visible +} diff --git a/test/files/run/t8015-ffc.scala b/test/files/run/t8015-ffc.scala new file mode 100644 index 0000000000..fe6781be42 --- /dev/null +++ b/test/files/run/t8015-ffc.scala @@ -0,0 +1,7 @@ + +object Test extends App { + val ms = """This is a long multiline string + with \u000d\u000a CRLF embedded.""" + assert(ms.lines.size == 3, s"lines.size ${ms.lines.size}") + assert(ms contains "\r\n CRLF", "no CRLF") +} -- cgit v1.2.3 From 8be560a1cf6306ea4ed2596f3b6631c2e44d8213 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Wed, 18 Dec 2013 01:26:34 -0800 Subject: 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. --- src/reflect/scala/reflect/internal/util/Position.scala | 11 ++++++++++- src/reflect/scala/reflect/internal/util/SourceFile.scala | 8 ++++++-- test/files/neg/t8015-ffb.check | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'test/files') diff --git a/src/reflect/scala/reflect/internal/util/Position.scala b/src/reflect/scala/reflect/internal/util/Position.scala index 15cfda26b5..dbee31bfca 100644 --- a/src/reflect/scala/reflect/internal/util/Position.scala +++ b/src/reflect/scala/reflect/internal/util/Position.scala @@ -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 = ( diff --git a/src/reflect/scala/reflect/internal/util/SourceFile.scala b/src/reflect/scala/reflect/internal/util/SourceFile.scala index 1da334d41f..39c4ac8a95 100644 --- a/src/reflect/scala/reflect/internal/util/SourceFile.scala +++ b/src/reflect/scala/reflect/internal/util/SourceFile.scala @@ -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 = diff --git a/test/files/neg/t8015-ffb.check b/test/files/neg/t8015-ffb.check index 90c8d045b4..9b2171ea47 100644 --- a/test/files/neg/t8015-ffb.check +++ b/test/files/neg/t8015-ffb.check @@ -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 -- cgit v1.2.3