diff options
author | Paul Phillips <paulp@improving.org> | 2011-08-08 06:55:12 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-08-08 06:55:12 +0000 |
commit | be31934db38a93468b6390e783ca377da6283c19 (patch) | |
tree | 9b2718d2b9e02dc8774c2e15bb9a2e1516c036cf | |
parent | 6fe5754cec7f389477e5aa29ef527916d5d615d0 (diff) | |
download | scala-be31934db38a93468b6390e783ca377da6283c19.tar.gz scala-be31934db38a93468b6390e783ca377da6283c19.tar.bz2 scala-be31934db38a93468b6390e783ca377da6283c19.zip |
Fix for a bug in CharArrayReader which made tri...
Fix for a bug in CharArrayReader which made triple quoted strings
fail to parse sometimes. Note: when the temptation strikes to adjust
for special cases by letting the regular case happen and subsequently
attempting to fix the ball of mutation by selectively applying what
seems like the inverse operation, please consider the possibility that
this is not the optimal approach. Closes SI-4785, no review.
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Scanners.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/CharArrayReader.scala | 6 | ||||
-rw-r--r-- | test/files/run/triple-quoted-expr.check | 5 | ||||
-rw-r--r-- | test/files/run/triple-quoted-expr.scala | 26 |
4 files changed, 35 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala index 27e7de59a7..e73af5ea86 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala @@ -344,10 +344,7 @@ trait Scanners extends ScannersCommon { nextChar() if (ch == '\"') { nextRawChar() - val saved = lineStartOffset getMultiLineStringLit() - if (lineStartOffset != saved) // ignore linestarts within a multi-line string - lastLineStartOffset = saved } else { token = STRINGLIT strVal = "" diff --git a/src/compiler/scala/tools/nsc/util/CharArrayReader.scala b/src/compiler/scala/tools/nsc/util/CharArrayReader.scala index aee87d8ad9..153334b5e1 100644 --- a/src/compiler/scala/tools/nsc/util/CharArrayReader.scala +++ b/src/compiler/scala/tools/nsc/util/CharArrayReader.scala @@ -47,7 +47,10 @@ abstract class CharArrayReader { self => } } - /** Advance one character, leaving CR;LF pairs intact */ + /** Advance one character, leaving CR;LF pairs intact. + * This is for use in multi-line strings, so there are no + * "potential line ends" here. + */ final def nextRawChar() { if (charOffset >= buf.length) { ch = SU @@ -56,7 +59,6 @@ abstract class CharArrayReader { self => ch = c charOffset += 1 if (c == '\\') potentialUnicode() - else if (c < ' ') potentialLineEnd() } } diff --git a/test/files/run/triple-quoted-expr.check b/test/files/run/triple-quoted-expr.check new file mode 100644 index 0000000000..4e59695f36 --- /dev/null +++ b/test/files/run/triple-quoted-expr.check @@ -0,0 +1,5 @@ + +hi +hi + +hi diff --git a/test/files/run/triple-quoted-expr.scala b/test/files/run/triple-quoted-expr.scala new file mode 100644 index 0000000000..6d91ac5888 --- /dev/null +++ b/test/files/run/triple-quoted-expr.scala @@ -0,0 +1,26 @@ +class A { + def f1 = { + val x = 5 + +""" +hi""" + } + def f2 = { + val x = 5 + + """hi""" + } + def f3 = { + val x = 5 + + "\nhi" + } +} + +object Test { + def main(args: Array[String]): Unit = { + val x = new A + import x._ + List(f1, f2, f3) foreach println + } +} |