-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
@@ -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)!; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/fake_async.dart
Outdated
initialTime ??= clock.now(); | ||
_clock = Clock(() => initialTime.add(elapsed)); | ||
_clock = Clock(() => initialTime!.add(elapsed)); |
There was a problem hiding this comment.
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));
There was a problem hiding this comment.
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
No description provided.