Skip to content

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

Merged
merged 1 commit into from
Feb 29, 2020
Merged

Conversation

som-snytt
Copy link
Contributor

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.

`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.
@scala-jenkins scala-jenkins added this to the 2.13.3 milestone Feb 28, 2020
@Ichoran
Copy link
Contributor

Ichoran commented Feb 28, 2020

I don't understand what is wrong with = _. If it's not pretty enough, maybe we need a prettier alias for _, maybe var x: B = 🌷.

@martijnhoekstra
Copy link
Contributor

var x: C = �

Copy link
Contributor

@hrhino hrhino left a 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]
Copy link
Contributor

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.

@som-snytt
Copy link
Contributor Author

@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 Predef-emoji.scala.

def 🌹[A] = null.asInstanceOf[A]

We already have
type 🌷[+A, +B] = Tuple2[A, B] // tulip/tuple

I'll ask on the ticket whether to consider
var v: Int =
which is visually striking, plus no need to remember flower names.

@som-snytt som-snytt merged commit 3a53faf into scala:2.13.x Feb 29, 2020
@dwijnand dwijnand modified the milestones: 2.13.3, 2.13.2 Feb 29, 2020
@dwijnand
Copy link
Member

It's too bad someone started accusing var x: A = _
of undue ugliness. That remains the best expression of
non-assignment.

I agree. Where's was it accused?

@som-snytt
Copy link
Contributor Author

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.

@som-snytt som-snytt deleted the issue/trav-null branch February 29, 2020 11:08
@dwijnand
Copy link
Member

Yeah, with scala/scala3#7789 there's even more of a case for distinguishing setting to null and uninitialised.

@SethTisue
Copy link
Member

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 null actually appearing in the code. null.asInstanceOf[T] has that, _ doesn't.

(But it's just an argument to be weighed against other arguments and considerations.)

mariogalic pushed a commit to mariogalic/scala that referenced this pull request Apr 8, 2021
- 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)
hamzaremmal pushed a commit to hamzaremmal/scala3 that referenced this pull request May 2, 2025
hamzaremmal pushed a commit to hamzaremmal/scala3 that referenced this pull request May 2, 2025
- 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)
hamzaremmal pushed a commit to scala/scala3 that referenced this pull request May 7, 2025
hamzaremmal pushed a commit to scala/scala3 that referenced this pull request May 7, 2025
- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants