-
Notifications
You must be signed in to change notification settings - Fork 21
by-name parameter does not work with function literal syntax #9313
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9313?orig=1 |
Saurabh Wadhawan (saurabh18e) said: |
@retronym said: scala> val f: (Boolean, => Int) => Int = (b, i) => if (b) i else 0
f: (Boolean, => Int) => Int = <function2>
scala> f(false, ???)
res0: Int = 0
scala> f(true, ???)
scala.NotImplementedError: an implementation is missing
at scala.Predef$.$qmark$qmark$qmark(Predef.scala:225) |
Saurabh Wadhawan (saurabh18e) said: but below doesn't work the by-name parameter symbol should be specified in the definition on RHS rather than in the type on LHS |
Saurabh Wadhawan (saurabh18e) said: scala> val f2: (=> Int) => Int = (i) => 1 |
The syntax specification says:
Is there a reason I'm not seeing why it can't be this?
|
Just a note that this is still an issue; someone ran into this today and asked about it on gitter. |
not fixed in Scala 3. this came up again on Gitter today. https://gitter.im/scala/scala?at=611c09487bc44d0a472893e0 scala> val x: (=> Int) => Int = (x: =>Int) => x
1 |val x: (=> Int) => Int = (x: =>Int) => x
| ^^
| an identifier expected, but '=>' found
scala> val x: (=> Int) => Int = (x: (=>Int)) => x
1 |val x: (=> Int) => Int = (x: (=>Int)) => x
| ^^^^^
| By-name parameter type => Int not allowed here.
scala> val x: (=> Int) => Int = (x: Int) => x
1 |val x: (=> Int) => Int = (x: Int) => x
| ^^^^^^^^^^^^^
| Found: Int => Int
| Required: (=> Int) => Int
scala> val x: (=> Int) => Int = x => x
val x: (=> Int) => Int = Lambda$1335/1897050650@3a17acd4 that's Scala 3, but Scala 2.13.6 gives similar errors. |
Cross-referencing proposal on Discourse: Make by-name parameters just sugar syntax rather than actual types |
scala> val v = (headVal: Int, currentResultStream: => Int) => head
:1: error: identifier expected but '=>' found.
val v = (headVal: Int, currentResultStream: => Int) => head
^
The text was updated successfully, but these errors were encountered: