This repository was archived by the owner on Dec 22, 2021. It is now read-only.
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
LazyList.#:: not lazy due to parser rewriting of right-associative infix operators #127
Closed
Description
Evaluating
def bleh(i: Int) = {println(s"bleh $i"); i}
val xs20 = bleh(1) #:: bleh(2) #:: bleh(3) #:: LazyList.empty
will immediately execute all the println
s, even though .force
is never called and .evaluated
remains false
. If one defines a left associative prepend
with the same definition as #::
, then
val x21 = LazyList.empty.prepend(bleh(3)).prepend(bleh(2)).prepend(bleh(1))
will behave in a properly lazy manner.
This is no great mystery, as the parser converts the definition of xs20
to:
val xs20 = { <synthetic> <artifact> val x$68 = bleh(1);
{ <synthetic> <artifact> val x$67 = bleh(2);
{ <synthetic> <artifact> val x$66 = bleh(3);
LazyList.empty.$hash$colon$colon(x$66)}.$hash$colon$colon(x$67)}.$hash$colon$colon(x$68) };
This seems to be scala/bug#7333, which was closed as a duplicate of the somewhat less general scala/bug#1980
Metadata
Metadata
Assignees
Labels
No labels