Skip to content

Commit 125b503

Browse files
committed
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.
1 parent 8e9e2e3 commit 125b503

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

src/compiler/scala/tools/nsc/ast/parser/Scanners.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,7 @@ trait Scanners extends ScannersCommon {
346346
nextChar()
347347
if (ch == '\"') {
348348
nextRawChar()
349-
val saved = lineStartOffset
350349
getMultiLineStringLit()
351-
if (lineStartOffset != saved) // ignore linestarts within a multi-line string
352-
lastLineStartOffset = saved
353350
} else {
354351
token = STRINGLIT
355352
strVal = ""

src/compiler/scala/tools/nsc/util/CharArrayReader.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ abstract class CharArrayReader { self =>
4747
}
4848
}
4949

50-
/** Advance one character, leaving CR;LF pairs intact */
50+
/** Advance one character, leaving CR;LF pairs intact.
51+
* This is for use in multi-line strings, so there are no
52+
* "potential line ends" here.
53+
*/
5154
final def nextRawChar() {
5255
if (charOffset >= buf.length) {
5356
ch = SU
@@ -56,7 +59,6 @@ abstract class CharArrayReader { self =>
5659
ch = c
5760
charOffset += 1
5861
if (c == '\\') potentialUnicode()
59-
else if (c < ' ') potentialLineEnd()
6062
}
6163
}
6264

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
hi
3+
hi
4+
5+
hi
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class A {
2+
def f1 = {
3+
val x = 5
4+
5+
"""
6+
hi"""
7+
}
8+
def f2 = {
9+
val x = 5
10+
11+
"""hi"""
12+
}
13+
def f3 = {
14+
val x = 5
15+
16+
"\nhi"
17+
}
18+
}
19+
20+
object Test {
21+
def main(args: Array[String]): Unit = {
22+
val x = new A
23+
import x._
24+
List(f1, f2, f3) foreach println
25+
}
26+
}

0 commit comments

Comments
 (0)