Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

migrate to null safety #18

Merged
merged 2 commits into from
Apr 10, 2020
Merged

migrate to null safety #18

merged 2 commits into from
Apr 10, 2020

Conversation

jakemac53
Copy link
Contributor

No description provided.

@@ -232,7 +233,7 @@ class FakeAsync {
for (;;) {
if (_timers.isEmpty) break;

var timer = minBy(_timers, (timer) => timer._nextCall);
var timer = minBy(_timers, (FakeTimer timer) => timer._nextCall)!;
Copy link
Member

Choose a reason for hiding this comment

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

What caused this? Does minBy always return nullable? Why do we need the argument type specified in the callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just for type inference purposes, it was inferring Object? before I added this.

I could explicitly add the generics but there are actually two so this is less verbose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also yes minBy returns nullable, because it returns null if the list is empty. This is one of the cases where we would possibly make a breaking change if we could, and throw an ArgumentError in that case instead.

initialTime ??= clock.now();
_clock = Clock(() => initialTime.add(elapsed));
_clock = Clock(() => initialTime!.add(elapsed));
Copy link
Member

Choose a reason for hiding this comment

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

@leafpetersen - is there some opportunity for flow analysis here?

Is there some way to use late that would avoid the overhead in this callback?

We could potentially do it manually.

final nonNullInitialTime = initialTime ?? clock.now();
_clock = Clock(() => nonNullInitialTime.add(elapsed));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will go ahead and do the workaround for now. I did open an issue about ??= on the sdk a while ago, dart-lang/sdk#41172

@jakemac53 jakemac53 merged commit a564218 into null_safety Apr 10, 2020
@jakemac53 jakemac53 deleted the null_safety_migration branch April 10, 2020 19:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants