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

withResource() when callback returns a future and strong mode errors #1550

Closed
adamlofts opened this issue Mar 30, 2017 · 0 comments · Fixed by dart-lang/pool#7
Closed

withResource() when callback returns a future and strong mode errors #1550

adamlofts opened this issue Mar 30, 2017 · 0 comments · Fixed by dart-lang/pool#7

Comments

@adamlofts
Copy link

The following code runs fine:

import 'package:pool/pool.dart';

main() async {
  Pool pool = new Pool(1);
  String s = await pool.withResource(() async => "Hi");
  print(s);
}

However in strong mode I get the following errors:

dartanalyzer --strong bin/testpool.dart
Analyzing [bin/testpool.dart]...
[error] Couldn't infer type parameter 'T'; 'Future' must be of type 'String'. (/home/adam/dev/fp3/dart/yacht/bin/testpool.dart, line 6, col 25)
[error] The argument type '() → Future' can't be assigned to the parameter type '() → String'. (/home/adam/dev/fp3/dart/yacht/bin/testpool.dart, line 6, col 38)
2 errors found.

I believe this is because withResource allows callback to return a T or Future<T> but this is not reflected in the function signature. Probably the type of callback should be: FutureOr<T> callback().

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

Successfully merging a pull request may close this issue.

2 participants