Skip to content

Handle implicit future unions in downwards inference #25322

Closed
@leafpetersen

Description

@leafpetersen

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
}

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.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