Skip to content
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
@pnf

Description

@pnf

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 printlns, 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions