-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expression for all zero bits #8767
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
Conversation
`null.asInstanceOf[A]` is more kosher than `0`. It doesn't matter here because the value is never used and is always re-assigned. It's too bad someone started accusing `var x: A = _` of undue ugliness. That remains the best expression of non-assignment.
I don't understand what is wrong with |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -723,7 +723,7 @@ trait IterableOnceOps[+A, +CC[_], +C] extends Any { this: IterableOnce[A] => | |||
throw new UnsupportedOperationException("empty.reduceLeft") | |||
|
|||
var first = true | |||
var acc: B = 0.asInstanceOf[B] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
News to me this even works.
@hrhino I noticed it looking at the de-reffing change, but I'll leave it to the experts. @Ichoran I've created a scala-dev ticket to add the alias to
We already have I'll ask on the ticket whether to consider |
I agree. Where's was it accused? |
I don't want to accuse without evidence, but I remember someone suggested deprecating the syntax so you'd have to seth it to null explicitly. |
Yeah, with scala/scala3#7789 there's even more of a case for distinguishing setting to null and uninitialised. |
Heh, I saw what you did there, Som. Yes, I believe I remember arguing as follows: we want to cut down on the number of different ways nulls can creep into our programs. I like it when sources of nulls involve the identifier (But it's just an argument to be weighed against other arguments and considerations.) |
- This seems to be the only place `0.asInstanceOf[T]` is used, usually it is expressed as `null.asInstanceOf[T]`. - Emulates [Expression for all zero bits scala#8767](scala#8767)
Expression for all zero bits
- This seems to be the only place `0.asInstanceOf[T]` is used, usually it is expressed as `null.asInstanceOf[T]`. - Emulates [Expression for all zero bits scala/scala#8767](scala/scala#8767)
Expression for all zero bits
- This seems to be the only place `0.asInstanceOf[T]` is used, usually it is expressed as `null.asInstanceOf[T]`. - Emulates [Expression for all zero bits scala/scala#8767](scala/scala#8767)
null.asInstanceOf[A]
is more kosher than0
.It doesn't matter here because the value is never used
and is always re-assigned.
It's too bad someone started accusing
var x: A = _
of undue ugliness. That remains the best expression of
non-assignment.