Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #11997: Declare object cons before class Cons. #9035

Merged
merged 1 commit into from Jun 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/library/scala/collection/immutable/Stream.scala
Expand Up @@ -357,6 +357,22 @@ sealed abstract class Stream[+A] extends AbstractSeq[A]
@SerialVersionUID(3L)
object Stream extends SeqFactory[Stream] {

/* !!! #11997 This `object cons` must be defined lexically *before* `class Cons` below.
* Otherwise it prevents Scala.js from building on Windows.
*/
/** An alternative way of building and matching Streams using Stream.cons(hd, tl).
*/
object cons {
/** A stream consisting of a given first element and remaining elements
* @param hd The first element of the result stream
* @param tl The remaining elements of the result stream
*/
def apply[A](hd: A, tl: => Stream[A]): Stream[A] = new Cons(hd, tl)

/** Maps a stream to its head and tail */
def unapply[A](xs: Stream[A]): Option[(A, Stream[A])] = #::.unapply(xs)
}

//@SerialVersionUID(3L) //TODO Putting an annotation on Stream.empty causes a cyclic dependency in unpickling
object Empty extends Stream[Nothing] {
override def isEmpty: Boolean = true
Expand Down Expand Up @@ -419,19 +435,6 @@ object Stream extends SeqFactory[Stream] {

}

/** An alternative way of building and matching Streams using Stream.cons(hd, tl).
*/
object cons {
/** A stream consisting of a given first element and remaining elements
* @param hd The first element of the result stream
* @param tl The remaining elements of the result stream
*/
def apply[A](hd: A, tl: => Stream[A]): Stream[A] = new Cons(hd, tl)

/** Maps a stream to its head and tail */
def unapply[A](xs: Stream[A]): Option[(A, Stream[A])] = #::.unapply(xs)
}

implicit def toDeferrer[A](l: => Stream[A]): Deferrer[A] = new Deferrer[A](() => l)

final class Deferrer[A] private[Stream] (private val l: () => Stream[A]) extends AnyVal {
Expand Down