dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.24k stars 1.57k forks source link

Clean up API boundaries when null-safety is non-optional. #40614

Open lrhn opened 4 years ago

lrhn commented 4 years ago

Current null-safe platform libraries have seemingly redundant null-checks in many places.

A parameter of type int should only contain integers, but if the function is called from a non-null-safe library, it can get away with passing null values anyway. To improve the error message in that case, we have inserted test which check that the value is indeed not null (mostly using ArgumentError.checkNotNull calls).

When null safety becomes non-optional (when language versions before the introduction of null safety stops being supported), those extra checks should be removed again.

This issue should be kept open until this has happened.

Known positions should use TODO(40614) as a reminder, or use checkNotNullable from dart:_internal, which is easy to search for.

asashour commented 1 year ago

I think this should be part of one of Dart 3 milestones.

lrhn commented 1 year ago

Most of the uses that I've touched are using the internal checkNotNullable, which should make them easy to remove. We may need to keep supporting non-null-safe code a little past the 3.0 release, for technical reasons, but removing unnecessary checks should be on the list for when we turn it off for good.

eseidel commented 8 months ago

Ran into one of these today. I presume this is possible now?