Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Issue 2016793002: Improve Future<T>.then<R> inference (Closed)

Created:
4 years, 7 months ago by Jennifer Messerly
Modified:
4 years, 6 months ago
Reviewers:
Leaf
CC:
reviews_dartlang.org
Base URL:
git@github.com:dart-lang/sdk.git@master
Target Ref:
refs/heads/master
Visibility:
Public.

Description

Improve 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 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+28 lines, -1 line) Patch
M pkg/analyzer/lib/src/generated/type_system.dart View 1 chunk +17 lines, -0 lines 0 comments Download
M pkg/analyzer/test/src/task/strong/inferred_type_test.dart View 1 chunk +8 lines, -0 lines 0 comments Download
M pkg/analyzer/test/src/task/strong/strong_test_helper.dart View 1 chunk +3 lines, -1 line 0 comments Download

Messages

Total messages: 8 (5 generated)
Jennifer Messerly
4 years, 7 months ago (2016-05-26 18:55:21 UTC) #5
Leaf
lgtm
4 years, 6 months ago (2016-05-26 23:01:32 UTC) #6
Jennifer Messerly
4 years, 6 months ago (2016-05-27 00:02:52 UTC) #8
Message was sent while issue was closed.
Committed patchset #1 (id:1) manually as
5fcf79c6180337231e02857b0c206ee64c23efcc (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698