Skip to content

Enable explicit-nulls and unsafe nulls by default with null under AnyVal#26296

Draft
HarrisL2 wants to merge 15 commits into
scala:mainfrom
HarrisL2:unsafe-explicit-nulls-under-anyval
Draft

Enable explicit-nulls and unsafe nulls by default with null under AnyVal#26296
HarrisL2 wants to merge 15 commits into
scala:mainfrom
HarrisL2:unsafe-explicit-nulls-under-anyval

Conversation

@HarrisL2

@HarrisL2 HarrisL2 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Testing the effects of AnyVal null by enabling it by default.

How much have you relied on LLM-based tools in this contribution?

Not at all

How was the solution tested?

Covered by existing tests (this is a refactoring)

sjrd and others added 15 commits February 28, 2026 10:02
That removes it from the top of the hierarchy, de-emphasizing its
importance.

It makes sense because it has all the properties of other `AnyVal`s:
"two" instances of `Null` "re-created" from the keyword `null` are
indistinguishible from each other. So it has structural equality.

This does not change the erasure of any type, because `AnyVal`
erases to `Object` anyway.

Unfortunately, this requires complicating the loading mechanism
for `scala.Null`. It now extends a class that can be compiled
from source, and that is incompatible with it being a "core"
class that is forced in `Definitions.init()`. We make it a
synthesized class instead, like the magic `FunctionN` classes.
I'm not happy about this. The silver lining is that, once we
actually move all-in to explicit-nulls, we will be able to define
`Null` itself in source, which will remove all of that magic.

If you have trouble wrapping your head around `Null <:< AnyVal`,
observe that `null: Null` and `(): Unit` have a lot in common.
They are both types with a singleton instance, accessible with
syntax. `null` is only `== null`, and `()` is only `== ()`.
Moreover, they do not have the `eq` operator.
@olhotak

olhotak commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

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.

3 participants