Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Future.wait([f1, f2]) does not have the correct return type #27134

Closed
scheglov opened this issue Aug 23, 2016 · 4 comments
Closed

Future.wait([f1, f2]) does not have the correct return type #27134

scheglov opened this issue Aug 23, 2016 · 4 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on

Comments

@scheglov
Copy link
Contributor

This code has a warning WARNING: Unsound implicit cast from List<dynamic> to List<List<A>> ([my_test] bin/test2.dart:6).

import 'dart:async';

foo() async {
  Future<List<A>> f1 = null;
  Future<List<A>> f2 = null;
  List<List<A>> merged = await Future.wait([f1, f2]);
}

class A {}

but if I extract [f1, f2] into a local variable, it does not have this warning.

import 'dart:async';

foo() async {
  Future<List<A>> f1 = null;
  Future<List<A>> f2 = null;
  var futures = [f1, f2];
  List<List<A>> resultsList = await Future.wait(futures);
}

class A {}
@scheglov scheglov added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-strong-mode labels Aug 23, 2016
@jmesserly
Copy link

jmesserly commented Aug 23, 2016

other workarounds, you could also put an explicit type on the list <Future<List<A>>>[f1, f2] or on the generic method var resultsList = await Future.wait/*<List<A>>*/(futures);.

but yeah, this should work. What should happen is await creates a T | F<T> downwards context, then generic method downward inference picks the F<T> branch because the return type of Future.wait is a Future<List>. However I'm not sure if either of those steps are currently implemented. I'm fairly sure the second one is not.

edit: fix what I wrote about Future.wait's type signature

@jmesserly
Copy link

the high level issue here is https://github.com/dart-lang/sdk/issues/25490, that downwards and upwards inference aren't unified. It's possible we push down List<Future<dynamic>> as the context for Future.wait's argument type. If we do that then it probably prevents the upwards ListLiteral inference that could otherwise easily figure out the list type argument (and thus, the generic method call on the way back up).

@jmesserly jmesserly self-assigned this Aug 24, 2016
@jmesserly jmesserly added the P2 A bug or feature request we're likely to work on label Aug 24, 2016
@jmesserly
Copy link

Guess above was correct. It was downwards generic method inference dropping the Future<T> possibility from T | Future<T>. Fixed in this CL: https://codereview.chromium.org/2280463002/

@scheglov
Copy link
Contributor Author

See also #27151.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

2 participants