Skip to content

Commit 7ba47c6

Browse files
nateboschCommit Queue
authored and
Commit Queue
committed
Remove some now unnecessary casts
Flow analysis has improved and issue #40041 is resolved. These `FutureOr<T>` conditionals are promoting to `Future<T>` or `T` and no longer need an explicit cast. [email protected] Change-Id: I925db6d7f52aad54c88434ff02e1d0ae4e72278b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331206 Reviewed-by: Lasse Nielsen <[email protected]> Commit-Queue: Ömer Ağacan <[email protected]> Reviewed-by: Stephen Adams <[email protected]> Reviewed-by: Sigmund Cherem <[email protected]> Auto-Submit: Nate Bosch <[email protected]> Reviewed-by: Martin Kustermann <[email protected]> Reviewed-by: Ömer Ağacan <[email protected]>
1 parent dbc4375 commit 7ba47c6

File tree

4 files changed

+6
-25
lines changed

4 files changed

+6
-25
lines changed

sdk/lib/_internal/js_runtime/lib/async_patch.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,7 @@ class _AsyncAwaitCompleter<T> implements Completer<T> {
195195
assert(!_future._isComplete);
196196
_future._chainFuture(value);
197197
} else {
198-
// TODO(40014): Remove cast when type promotion works.
199-
// This would normally be `as T` but we use `as dynamic` to make the
200-
// unneeded check be implicit to match dart2js unsound optimizations in
201-
// the user code.
202-
_future._completeWithValue(value as dynamic);
198+
_future._completeWithValue(value);
203199
}
204200
}
205201

sdk/lib/async/future.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,7 @@ abstract interface class Future<T> {
303303
factory Future.sync(FutureOr<T> computation()) {
304304
try {
305305
var result = computation();
306-
if (result is Future<T>) {
307-
return result;
308-
} else {
309-
// TODO(40014): Remove cast when type promotion works.
310-
return new _Future<T>.value(result as dynamic);
311-
}
306+
return result is Future<T> ? result : _Future<T>.value(result);
312307
} catch (error, stackTrace) {
313308
var future = new _Future<T>();
314309
AsyncError? replacement = Zone.current.errorCallback(error, stackTrace);
@@ -713,8 +708,7 @@ abstract interface class Future<T> {
713708
result.then(nextIteration, onError: doneSignal._completeError);
714709
return;
715710
}
716-
// TODO(40014): Remove cast when type promotion works.
717-
keepGoing = result as bool;
711+
keepGoing = result;
718712
}
719713
doneSignal._complete(null);
720714
});

sdk/lib/async/future_impl.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,7 @@ class _Future<T> implements Future<T> {
630630
}
631631
} else {
632632
_FutureListener? listeners = _removeListeners();
633-
// TODO(40014): Remove cast when type promotion works.
634-
// This would normally be `as T` but we use `as dynamic` to make the
635-
// unneeded check be implicit to match dart2js unsound optimizations in
636-
// the user code.
637-
_setValue(value as dynamic); // Value promoted to T.
633+
_setValue(value);
638634
_propagateToListeners(this, listeners);
639635
}
640636
}
@@ -673,11 +669,7 @@ class _Future<T> implements Future<T> {
673669
_chainFuture(value);
674670
return;
675671
}
676-
// TODO(40014): Remove cast when type promotion works.
677-
// This would normally be `as T` but we use `as dynamic` to make the
678-
// unneeded check be implicit to match dart2js unsound optimizations in the
679-
// user code.
680-
_asyncCompleteWithValue(value as dynamic); // Value promoted to T.
672+
_asyncCompleteWithValue(value);
681673
}
682674

683675
/// Internal helper function used by the implementation of `async` functions.

sdk/lib/async/stream.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,7 @@ abstract mixin class Stream<T> {
810810
subscription.pause();
811811
newValue.then(add, onError: addError).whenComplete(resume);
812812
} else {
813-
// TODO(40014): Remove cast when type promotion works.
814-
controller.add(newValue as dynamic);
813+
controller.add(newValue);
815814
}
816815
});
817816
controller.onCancel = subscription.cancel;

0 commit comments

Comments
 (0)