Skip to content

Should an is FutureOr<T> test make T a type of interest? #4362

Open
@eernstg

Description

@eernstg

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    flow-analysisDiscussions about possible future improvements to flow analysissmall-featureA small feature which is relatively cheap to implement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions