Skip to content

Enable explicit-nulls and unsafeNulls by default#25461

Draft
HarrisL2 wants to merge 8 commits intoscala:mainfrom
HarrisL2:unsafe-explicit-nulls
Draft

Enable explicit-nulls and unsafeNulls by default#25461
HarrisL2 wants to merge 8 commits intoscala: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 from a7fcb84 to 82f4571 Compare March 15, 2026 04:04
@HarrisL2 HarrisL2 force-pushed the unsafe-explicit-nulls branch 4 times, most recently from 34c011b to ca8fe2e Compare March 21, 2026 05:23
@HarrisL2 HarrisL2 force-pushed the unsafe-explicit-nulls branch 4 times, most recently from be6217e to 6268fa4 Compare March 26, 2026 13:29
@HarrisL2 HarrisL2 force-pushed the unsafe-explicit-nulls branch from 6268fa4 to b51acda Compare March 26, 2026 13:42
@deprecated(message = "This flag has no effect and will be removed in a future version.", since = "3.7.0")
val YnoKindPolymorphism: Setting[Boolean] = BooleanSetting(ForkSetting, "Yno-kind-polymorphism", "Disable kind polymorphism. (This flag has no effect)", deprecation = Deprecation.removed())
val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Make reference types non-nullable. Nullable types can be expressed with unions: e.g. String|Null.")
val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Since explicit nulls is enabled by default, this flage now enables safe nulls for explicit-nulls")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Since explicit nulls is enabled by default, this flage now enables safe nulls for explicit-nulls")
val YexplicitNulls: Setting[Boolean] = BooleanSetting(ForkSetting, "Yexplicit-nulls", "Since explicit nulls is enabled by default, this flag now enables safe nulls for explicit-nulls")

@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.

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