summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Scanners.scala3
-rw-r--r--src/compiler/scala/tools/nsc/util/CharArrayReader.scala6
-rw-r--r--src/library/scala/collection/immutable/Stream.scala10
-rw-r--r--test/files/run/t4835.check7
-rw-r--r--test/files/run/t4835.scala38
-rw-r--r--test/files/run/triple-quoted-expr.check5
-rw-r--r--test/files/run/triple-quoted-expr.scala26
7 files changed, 88 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
index 3208615757..b90b55afc5 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
@@ -346,10 +346,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 3499ab86fd..6f929a0a80 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/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala
index 79ff1bb197..057cde9e41 100644
--- a/src/library/scala/collection/immutable/Stream.scala
+++ b/src/library/scala/collection/immutable/Stream.scala
@@ -930,13 +930,19 @@ self =>
/** A specialized, extra-lazy implementation of a stream iterator, so it can
* iterate as lazily as it traverses the tail.
*/
-final class StreamIterator[+A](self: Stream[A]) extends Iterator[A] {
+final class StreamIterator[+A] private() extends Iterator[A] {
+ def this(self: Stream[A]) {
+ this()
+ these = new LazyCell(self)
+ }
+
// A call-by-need cell.
class LazyCell(st: => Stream[A]) {
lazy val v = st
}
- private var these = new LazyCell(self)
+ private var these: LazyCell = _
+
def hasNext: Boolean = these.v.nonEmpty
def next: A =
if (isEmpty) Iterator.empty.next
diff --git a/test/files/run/t4835.check b/test/files/run/t4835.check
new file mode 100644
index 0000000000..531c3d7bb6
--- /dev/null
+++ b/test/files/run/t4835.check
@@ -0,0 +1,7 @@
+-1 0 1 2 3 4 5 6 7 8 9
+-1 1 3 5 7 9 11 13 15 17 19
+1 1
+2 1 2
+2 1 A 2
+3 1 2 3
+3 1 A 2 B 3
diff --git a/test/files/run/t4835.scala b/test/files/run/t4835.scala
new file mode 100644
index 0000000000..50d161be40
--- /dev/null
+++ b/test/files/run/t4835.scala
@@ -0,0 +1,38 @@
+/*
+ * Test case for SI-4835. This tests confirm that the fix
+ * doesn't break laziness. To test memory consumption,
+ * I need to confirm that OutOfMemoryError doesn't occur.
+ * I could create such tests. However, such tests consume
+ * too much time and memory.
+ */
+object Test {
+ private final val INFINITE = -1
+ def testStreamIterator(num: Int, stream: Stream[Int]): Unit = {
+ val iter = stream.iterator
+ print(num)
+ // if num == -1, then steram is infinite sequence
+ if (num == INFINITE) {
+ for(i <- 0 until 10) {
+ print(" " + iter.next())
+ }
+ } else {
+ while(iter.hasNext) {
+ print(" " + iter.next())
+ }
+ }
+ println()
+ }
+
+ def main(args: Array[String]): Unit = {
+ import Stream.{from, cons, empty}
+ testStreamIterator(INFINITE, from(0))
+ testStreamIterator(INFINITE, from(0).filter(_ % 2 == 1))
+ testStreamIterator(1, Stream(1))
+ testStreamIterator(2, Stream(1, 2))
+ //Stream with side effect
+ testStreamIterator(2, cons(1, cons({ print(" A"); 2}, empty)))
+ testStreamIterator(3, Stream(1, 2, 3))
+ //Stream with side effect
+ testStreamIterator(3, cons(1, cons({ print(" A"); 2}, cons({ print(" B"); 3}, Stream.empty))))
+ }
+}
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
+ }
+}