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

Analyzer shouldn't recursively flatten futures #32881

Closed
natebosch opened this issue Apr 13, 2018 · 2 comments

Comments

@natebosch
Copy link
Member

commented Apr 13, 2018

I hit some code that has no errors or warnings with dartanalyzer --strong but has parse errors with dart --preview-dart-2. Here's a contrived demo:

import 'dart:async';

void main() async {
  print(await stuff());
}

Future<String> stuff() async {
  return moreStuff<Future<String>>(new Future.value('stuff'));
}

Future<T> moreStuff<T>(T value) async => value;

Running with dart --preview-dart-2 gives:

file:///tmp/nested_futures.dart:8:10: Error: A value of type 'dart.async::Future<dart.async::Future<dart.core::String>>' can't be assigned to a variable of type 'dart.async::FutureOr<dart.core::String>'.
Try changing the type of the left hand side, or casting the right hand side to 'dart.async::FutureOr<dart.core::String>'.
  return moreStuff<Future<String>>(new Future.value('stuff'));
         ^
file:///tmp/nested_futures.dart:8:10: Error: A value of type 'dart.async::Future<dart.async::Future<dart.core::String>>' can't be assigned to a variable of type 'dart.async::FutureOr<dart.core::String>'.
Try changing the type of the left hand side, or casting the right hand side to 'dart.async::FutureOr<dart.core::String>'.
  return moreStuff<Future<String>>(new Future.value('stuff'));
         ^

Real world code is fixed in dart-lang/test#810

@leafpetersen

This comment has been minimized.

Copy link
Member

commented Jun 7, 2018

@bwilkerson I'm going to take this unless you're actively working on it, since it relates to something else I'm fixing.

@bwilkerson

This comment has been minimized.

Copy link
Member

commented Jun 7, 2018

Feel free. I haven't started looking at it.

dart-bot pushed a commit that referenced this issue Jun 15, 2018
Fix various bugs and regularize behavior of returns statements in
various kinds of functions.

Closes-bug: #31887
Closes-bug: #30638
Closes-bug: #32233
Closes-bug: #32881
Closes-bug: #31278
Change-Id: I4ebd7e71096d611e189b571ba5de2998dd11c98b
Reviewed-on: https://dart-review.googlesource.com/60300
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>

@dgrove dgrove closed this Jun 15, 2018

@dgrove dgrove added this to Done in 2.0 language via automation Jun 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4 participants
You can’t perform that action at this time.