Skip to content
0:00 / 0:00

#dart#nullsafety#typepromotion

Null safety and subclasses in Dart - the devious coin trick

Randal L. Schwartz on Dart and Flutter

2.9K subscribers • 7 videos on Hallway

YouTube
  • Recommended by 1 person: 1 in engineering communities.
  • Presented by Randal L. Schwartz
  • May be out of date. The tools, versions or practices it shows have likely moved on.

Intermediate. Assumes working knowledge.

914 views5 years ago1 recommendation

Programming languagesLanguage design and type systems

Randal L. Schwartz explains why the Dart analyzer cannot guarantee type promotion for nullable instance variables due to potential getter overrides in subclasses.

Randal demonstrates why the analyzer can’t guarantee that once a null check has been processed, the value is definitely not null for further steps. UPDATE: See how to fix this in Dart 3! youtube.com/shorts/4mdrQW7rK18 Support Randal on Patreon via patreon.com/randalschwartz Or buy Randal a Coffee via buymeacoffee.com/randalschwartz

Why it's here

1 person recommends this

What people say. Recommended to explain why Dart does not automatically promote nullable instance variables to non-nullable after a null check.

u/RandalSchwartzin r/FlutterDev • Recommends

On “Does Flutter/Dart have GIL?”

> You can still have nightmares with single threaded async code - this is why you need to copy any nullable object state variables for them to be promoted, otherwise they need ! every time even if you check for null multiple times in the same method. This is flat out wrong. The problem isn't async. It's "getters" that might be overriding properties. A getter isn't required to return the same value twice. I did a video on this (link to this video and followed it up with a Dart 3 update (link to this video Watch those to understand why the problem has NOTHING to do with async.