-
Notifications
You must be signed in to change notification settings - Fork 18
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
Proposal: Add void to Predef #43
Comments
the main previous discussion I can think of is scala/scala#9161 , perhaps there are others given that both |
going through |
|
AFAIK there are some problems with that one. First, it can not be reused like you can not (or couldn't in previous versions) to do this val _ = foo
val _ = bar Also, I remember there was something funny about the way it was treated by the compiler.
Actually didn't know about this one, a quick test in a shell seems to work but will try latter on a real project using sbt-tpolecat.
A plus is that this one also works for unused values.
Yeah, also the Seq of the varargs. |
On Scala 2.12.12 there isn't a great solution: spurious "a pure expression does nothing" warning (awkward to suppress in 2.12, prone to occur in sbt builds) scala/bug#12112 To workaround that sbt now includes /** This works around Scala 2.12.12's
* "a pure expression does nothing in statement position"
*
* {{{
* Def.unit(copyResources.value)
* Def.unit(compile.value)
* }}}
*/
def unit(a: Any): Unit = () since sbt/sbt#5743. If |
For scala-library-next, 2.12 doesn't matter. Even 2.13 and 3.0 don't matter. We shouldn't add anything here unless it will be needed in the Scala-3-only world we will eventually be in. |
Doesn't the warning occur only in end-of-block position? I do the following now, which I think is also clear intention when reading the code: def file: java.io.File
def cleanUp(): Unit = {
file.delete()
()
} |
Ok, I just tested in a project (using Scala So, for now, I am closing this. However, I believe we can take something positive about this and it is that such techniques should be documented somewhere. I think it is fair to say that sbt-tpolecat is somewhat common and even without it I would like to contribute with such documentation, but I am not sure where would be the best place. But, I believe such a question is a bit off-topic for this issue and this repo in general, so I am moving the discussion to gitter. EditFor the record: here are the docs. |
maybe people will google it and find this ticket :-) (I am joking, yet also partly serious) |
To spruce up the potential google juice, maybe those googling for how to fix or suppress the phrase "discarded non-Unit value" will end up here too now that I've added it, and put some potential search phrases next to it. |
I have found this little helper (courtesy of Rob) to be very useful. Especially when you enable compiler options like
-Wvalue-discard
or-Wunused:implicits
(and friends)While adding this into all of my projects is not really "painful" I would like if this would be part of Predef.
So I thought this would be the right place to start a discussion about if it would be worth it to add it; and if such addition could be done here until
3.1
?The text was updated successfully, but these errors were encountered: