Skip to content

Analyzer shouldn't recursively flatten futures #32881

Closed
@natebosch

Description

@natebosch

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions