Skip to content

Handle implicit future unions in downwards inference #25322

Closed
@leafpetersen

Description

Various context in Dart essentially treat Future<T> as an implicit union type Future<T> | T. For example, await allows either:

void test() async {
  List<int> x = await [4]; 
  List<int> y = await new Future.value([4]);
}

Downwards inference currently only considers the Future<int> possibility here, and hence will infer type parameters for the Future creation and the list literal in the second await, but not for the list literal in the first await. It would be useful to support both.

Other examples of this include the return value for the lambda argument to Future.then, and values returned from async functions:

Future<List<int>> test() async {
  return [4];  // Currently inferred
  return new Future.value([4]); // Currently not inferred
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onarea-analyzerUse area-analyzer for Dart analyzer issues, including the analysis server and code completion.type-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions