Yesterday there was a discussion on the Dart community discord on doing something like this:
class Platform {
Object? core;
}
late final Platform? _corePlatform;
void main() {
// Have both the _platform_ and the _core_ bound to a name
// & checked for being non-null
if (_corePlatform case Platform(:final Object core)) {
print("${_corePlatform.core} $core");
}
}
The example program doesn't type check, because _corePlatform is not promoted from Platform? to Platform, even though Platform(:final Object core)) implies this to be true.
Doing this solves the problem:
if (_corePlatform case final Platform platform && Platform(:final Object core)) {
print("${platform.core} $core");
}
but it would be nice if it wasn't necessary.