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

Unified Diff: pkg/analyzer/lib/src/generated/type_system.dart

Issue 2016793002: Improve Future<T>.then<R> inference (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/type_system.dart
diff --git a/pkg/analyzer/lib/src/generated/type_system.dart b/pkg/analyzer/lib/src/generated/type_system.dart
index 19b5be5fdb2120fcfec3753681271abc4210e954..f34e7e67fda6049ce5bf5af7d85e1c24fce63d83 100644
--- a/pkg/analyzer/lib/src/generated/type_system.dart
+++ b/pkg/analyzer/lib/src/generated/type_system.dart
@@ -203,6 +203,23 @@ class StrongTypeSystemImpl extends TypeSystem {
var inferringTypeSystem =
new _StrongInferenceTypeSystem(typeProvider, fnType.typeFormals);
+ // Special case inference for Future.then.
+ //
+ // We don't have union types, so Future<T>.then<S> is typed to take a
+ // callback `T -> S`. However, the lambda might actually return a
+ // Future<S>. So we handle that special case here.
+ Element element = fnType?.element;
+ bool isFutureThen = element is MethodElement &&
+ element.name == 'then' &&
+ element.enclosingElement.type.isDartAsyncFuture;
+ if (isFutureThen &&
+ argumentTypes.isNotEmpty &&
+ argumentTypes[0] is FunctionType) {
+ // Ignore return context. We'll let the onValue function's return type
+ // drive inference.
+ returnContextType = null;
+ }
+
if (returnContextType != null) {
inferringTypeSystem.isSubtypeOf(fnType.returnType, returnContextType);
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698