Chromium Code Reviews
DescriptionImprove Future<T>.then<R> inference
This is not a general fix, but it's a simplest fix I could come up with.
It fixes the common problem of downwards and upwards inference conflicting. On the way down, we use the return context, but on the way back up, we ignore it for `Future.then`. This allows inference to conclude an instantiation like:
f.then/*<Future<int>>*/(...)
Then, thanks to Future flattening, we get the right return type as well (return type is Future<R>, which strong mode interprets as Future< flatten(R) >, so it works out).
Many of the other example cases are not fixed, though. Downwards inference will only push down `R` not `Future<R> | R`, so if the Future<R> branch was needed, for example: Future<Lint<int>> g = f.then(() => new Future.value([])) will not infer the `<int>[]` allocation nor the `Future<List<int>>` type. I have a work-in-progress that fixes those but introduces a special union type notion for `Future<R> | R`, and I'm not sure we're ready for that.
R=leafp@google.com
Committed: https://github.com/dart-lang/sdk/commit/5fcf79c6180337231e02857b0c206ee64c23efcc
Patch Set 1 #
Messages
Total messages: 8 (5 generated)
|
|||||||||||||||||||||||||||||||||||||