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

impossible to write non-strict right-associative operator #7333

Closed
scabug opened this issue Apr 4, 2013 · 2 comments
Closed

impossible to write non-strict right-associative operator #7333

scabug opened this issue Apr 4, 2013 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Apr 4, 2013

Due to the rewrite of right-associative operators as described in 6.12.3 it's effectively impossible to write a nonstrict right-associative operator; anything you pass will get forced.

I'm guessing this has been reported before and can't be fixed because it would change the meaning of a lot of code, but I couldn't find an obvious duplicate.

// Surprising behavior
object WAT extends App {
 
  object Foo {
    def !:(n: => Any) = "foo"
  }
 
  lazy val a = { println("AAA"); 1 }
  lazy val b = { println("BBB"); 1 }
  
  Foo.`!:`(a) // ok
 
  b !: Foo    // rewritten as { val x = b; Foo.`!:`(x) } 
              // per 6.12.3 and thus forces `b`, oops
 
}
 
// output is BBB
@scabug
Copy link
Author

scabug commented Apr 4, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7333?orig=1
Reporter: Rob Norris (rnorris)
Duplicates #1980

@scabug
Copy link
Author

scabug commented Apr 21, 2013

@paulp said:
You're right on all counts. It's #1980, and it probably can't be fixed.

val x = f() #:: g() #:: Stream.Nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants