Description
Following up on #4361, here comes a similar consideration:
We might want to make T
a type of interest when FutureOr<T>
is a type of interest. This is motivated by the fact that we already do the same thing for the other union type T?
. With FutureOr
, the other operand may even be considered: When FutureOr<T>
is of interest, Future<T>
might also be of interest.
FutureOr<int> bar() => 42;
Future<int> foo(bool urgent, FutureOr<int> x) async {
if (urgent) {
if (x is Future<int>) x = 24; // Don't await it!
} else {
x = await x;
}
x.isEven; // This should be possible here.
...
}
This example may be somewhat artificial, but it illustrates that the type int
could be of interest based on the fact that FutureOr<int>
is already on the table.
Finally, we could consider making FutureOr<T>
of interest whenever T
is of interest, or Future<T>
is of interest. This one seems more far-fetched because it might introduce futures into a context where absolutely nothing points in that direction. Nevertheless,