Skip to content

Enable explicit-nulls and unsafeNulls by default#25461

Draft
HarrisL2 wants to merge 10 commits into
scala:mainfrom
HarrisL2:unsafe-explicit-nulls
Draft

Enable explicit-nulls and unsafeNulls by default#25461
HarrisL2 wants to merge 10 commits into
scala:mainfrom
HarrisL2:unsafe-explicit-nulls

Conversation

@HarrisL2
Copy link
Copy Markdown
Contributor

@HarrisL2 HarrisL2 commented Mar 9, 2026

As the next steps to enabling explicit-nulls by default, we try to enable unsafeNulls along with it. Additionally, we will add a safeNulls language option that allows safeNulls to be toggled on in desired contexts.

The reason for this seemingly redundant change is due to the nature of the explicit-nulls flag. Explicit nulls is a global change that changes the type system, making Null no longer a subtype of AnyRef. As such, it cannot be toggled on and off locally.

On the other hand, unsafeNulls is a local option that allows T | Null to be a subtype of T. Along with the safeNulls import, we will be able decide whether of not to enable safe null behavior on a file-by-file or even scope-by-scope basis.

If full-program safeNulls is desired, we would use -langauge:safeNulls to import it globally.

@HarrisL2 HarrisL2 force-pushed the unsafe-explicit-nulls branch 5 times, most recently from 34c011b to ca8fe2e Compare March 21, 2026 05:23
@HarrisL2 HarrisL2 force-pushed the unsafe-explicit-nulls branch 6 times, most recently from 0f4bdab to dc4c10f Compare March 26, 2026 20:49
Comment thread compiler/src/dotty/tools/dotc/config/ScalaSettings.scala Outdated
@olhotak
Copy link
Copy Markdown
Contributor

olhotak commented Mar 27, 2026

@WojciechMazur could you please run the Open Community Build on this PR?

@olhotak
Copy link
Copy Markdown
Contributor

olhotak commented Apr 18, 2026

Open Community Build results here:
https://scala3.westeurope.cloudapp.azure.com/dashboard/compare?baseScalaVersion=3.8.4-RC1-bin-20260313-3be6338-NIGHTLY&targetScalaVersion=3.8.4-RC1-bin-20260327-d584de7

Most of the issues are macros that don't support FlexibleType.

There's a few with #25733
A few with #25808
A few with #25722

And a handful of others (to be minimized):
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/facsimile/facsimile/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/gekomad/scala-regex-collection/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/karelcemus/play-redis/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/kubuszok/hearth/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/kubuszok/pipez/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/memo33/scdbpf/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/neandertech/langoustine/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/philwalk/uni/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/sake92/sharaf/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/scalamock/scalamock/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/softwaremill/tapir/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs
https://scala3.westeurope.cloudapp.azure.com/dashboard/projects/stk-code/scalaveusz/builds/HarrisL2%2Fscala3%3Aunsafe-explicit-nulls%3A2026-04-01/logs

@HarrisL2
Copy link
Copy Markdown
Contributor Author

karelcemus/play-redis and scalamock/scalamock are the same underlying issue in scalamock's implementation, and has been reported as an issue at scalamock/scalamock#734

@HarrisL2
Copy link
Copy Markdown
Contributor Author

neandertech/langoustine is apparently an existing bug and a fix has been proposed at #25940

@HarrisL2
Copy link
Copy Markdown
Contributor Author

All other remaining failures are not related to the changes on this branch.

@olhotak
Copy link
Copy Markdown
Contributor

olhotak commented May 27, 2026

Now that 3.10 has been started, this should be rebased, the open community build run again, and hopefully merged. The only blocker to doing so as far as I'm aware is #25940 . @noti0na1 could you please have a look at the new approach in #25940 ?

@HarrisL2 HarrisL2 force-pushed the unsafe-explicit-nulls branch 6 times, most recently from a4de495 to b92811d Compare May 29, 2026 20:44
@HarrisL2 HarrisL2 force-pushed the unsafe-explicit-nulls branch from b92811d to 08125eb Compare May 29, 2026 21:32
@olhotak
Copy link
Copy Markdown
Contributor

olhotak commented May 29, 2026

@WojciechMazur could you please run the Open Community Build on this again?

@olhotak
Copy link
Copy Markdown
Contributor

olhotak commented Jun 1, 2026

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.

2 participants