Surprising wrapping of Future<X?> within Future<Object> #48845
Labels
area-devexp
For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
devexp-warning
Issues with the analyzer's Warning codes
P2
A bug or feature request we're likely to work on
type-enhancement
A request for a change that isn't a bug
I've encountered a weird bug stemming from Dart's handling of generics/futures. Consider the following snippet:
Here the
_promoted()
method returns a Future wrapping the future from_nestedFuture()
, while the_notPromoted()
method returns the result of_nestedFuture()
directly. The issue lies in the fact thatFuture<Object?>
is not assignable toFuture<Object>
, but is assignable toObject
, and hence the compiler wraps one future in another, andawait _promoted()
returns the future from_nestedFuture()
.It might not be against specification of the Dart language, but I would appreciate if such wrapping returned an analyzer warning about a potential misuse of Futures.
Dart SDK version: 2.16.2 (stable), reproducible on DartPad as well as Android/JIT (haven't checked other platforms).
The text was updated successfully, but these errors were encountered: