8000 [breaking change] Discontinue non-null-safe mode · Issue #49530 · dart-lang/sdk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[breaking change] Discontinue non-null-safe mode #49530
Closed
@mit-mit

Description

@mit-mit

Dart 3 & discontinuation of support for non-sound null safety

Background

In the Dart 2.12 release, Dart introduced sound null safety. When this was introduced we used an opt-in model: Only code that was opting into language version 2.12 or later was run with null safety. Dart developers could migrate their code in a stepwise fashion.

We are now planning a Dart 3 release -- tentatively slated for release by mid-2023 -- where we plan on only supporting Dart code that uses full sound null safety. This means that the null safety legacy mode will be discontinued, and that all code must run with full sound null safety.`

The reasons for making this change are:

  • Supporting both unsound and sound null safety adds overhead and complexity. Dart developers need to learn and understand both modes. Whenever reading a piece of Dart code, you need to check the language version to see if types are non-null by default (2.12 and later) or nullable by default (versions below 2.12)

  • Having to support both modes in our compilers and runtimes slows us down in terms of evolving the Dart SDK to support new features.

  • Our statistics on both packages on pub.dev and the null safety mode in which Flutter apps run, show that the ecosystem has largely already migrated to full sound null safety, and thus is ready 8000 to turn off unsound null safety/legacy mode.

Everything uses sound null safety in Dart 3

In Dart 3, only sound null safety is supported.
Concretely this implies that Dart 3 will not support:

  1. Code using an SDK constraint where the min-constraint isn't at least 2.12 (e.g. sdk: ">=2.7.0" will be disallowed and won't resolve).

  2. Libraries using per-library language version markers selecting versions less than 2.12 (e.g. // @dart=2.9 will be disallowed).

Backwards compatibility for null safe packages

Dart 3 sound null safety will be backwards compatible with with code already migrated to use null safety in language versions 2.12 and later.

This means that a Dart 3.0 SDK will allow SDK constraints where the lower-bound is at least 2.12, even when the SDK upper-bound only allows versions less than 3 (<3.0). For example, a package with the following constraint will be allowed to resolve with a Dart 3.x SDK:

environment:
  sdk: '>=2.12.0 <3.0.0'

This allows developers to use Dart 3 sound null safety with packages that have been migrated to 2.12 null safety.

Note that Dart 3 may contain other breaking changes. For example some core library APIs are discontinued in Dart 3, which may mean that some packages may not be compatible with Dart 3 even if they have migrated to null safety with 2.12. We'll release a Dart 3 alpha release (see below) that can be used to test if code is affected by any of these breaking changes.

Roll out plan

We expect to roll out a Dart 3 alpha release several months prior to Dart 3 stable. This release will allow for testing if a package or app is compatible with Dart 3. The alpha release is not likely to contain other Dart 3 feature work unrelated to sound null safety, but will contain all planned breaking changes.

Later we also plan on releasing a Dart 3 beta release that is more feature complete.

Finally, we'll release the Dart 3.0 stable release, tentatively by mid-2023.

Work item tracking

Dart 2.19 stable, and associated Flutter stable

Dart 3 alpha

Dart 3 beta

Metadata

Metadata

Assignees

Labels

area-metaCross-cutting, high-level issues (for tracking many other implementation issues, ...).enhancement-breaking-changeAn enhancement which is breaking.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0