Analyzer should report a hint when a Future.then() callback fails to return the proper type. #18531
Labels
analyzer-warning
Issues with the analyzer's Warning codes
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
type-enhancement
A request for a change that isn't a bug
The following code illustrates a mistake I have made frequently, and would like the analyzer to issue a hint about:
import 'dart:async';
Future foo(int i) {
return new Future(() {});
}
Future<int> bar() {
return foo(1).then(() {
/* return */ foo(2).then(() {
return 5;
});
});
}
I meant to create a method bar() that would perform foo(1) asynchronously, then perform foo(2) asynchronously, then complete the result with the number 5. However, because I left out a "return" keyword, the closure passed to foo(1).then() returns null. (Uncommenting the "return" keyword fixes the mistake).
It would be nice if the analyzer could infer that the closure passed to foo(1).then() was intended to return either an int or a Future<int>, and issue a warning to tell me that it's returning null instead.
The text was updated successfully, but these errors were encountered: