diff --git a/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/LazyList.scala b/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/LazyList.scala index bc816512..1c82f4c3 100644 --- a/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/LazyList.scala +++ b/compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/LazyList.scala @@ -365,7 +365,7 @@ final class LazyList[+A] private (private[this] var lazyState: () => LazyList.St newLL { if (isEmpty) suffix match { case lazyList: LazyList[B] => lazyList.state // don't recompute the LazyList - case _ => stateFromIterator(suffix.toIterator) + case coll => stateFromIterator(coll.toIterator) } else sCons(head, tail lazyAppendedAll suffix) } diff --git a/compat/src/test/scala/test/scala/collection/LazyListTest.scala b/compat/src/test/scala/test/scala/collection/LazyListTest.scala index 924d0c01..635295d9 100644 --- a/compat/src/test/scala/test/scala/collection/LazyListTest.scala +++ b/compat/src/test/scala/test/scala/collection/LazyListTest.scala @@ -355,7 +355,7 @@ class LazyListTest { assertEquals(1 to 10, build(_ ++= LazyList.from(1).take(10))) assertEquals(1 to 10, build(_ ++= Iterator.from(1).take(10))) } - + @Test def selfReferentialFailure(): Unit = { def assertNoStackOverflow[A](lazyList: LazyList[A]): Unit = { @@ -372,4 +372,12 @@ class LazyListTest { assertNoStackOverflow((new L).a) assertNoStackOverflow((new L).b) } + + // scala/bug#11931 + @Test + def lazyAppendedAllExecutesOnce(): Unit = { + var count = 0 + LazyList(1).lazyAppendedAll({ count += 1; Seq(2)}).toList + assertEquals(1, count) + } }