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

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

Issue 2208953002: fix #25944, improve Future.then inference (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix names, relationship between FutureUnion and DartType Created 4 years, 4 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
Index: pkg/analyzer/lib/src/generated/static_type_analyzer.dart
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index fa82560e055276642182e1a99c6336ffe21b0717..2b09908338aa780f33200fc1b74ee0dd4c912fb1 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -518,7 +518,13 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
// * BlockFunctionBody, if we inferred a type from yield/return.
// * we also normalize bottom to dynamic here.
if (_strongMode && (computedType.isBottom || computedType.isDynamic)) {
- computedType = InferenceContext.getType(body) ?? _dynamicType;
+ DartType contextType = InferenceContext.getContext(body);
+ if (contextType is FutureUnionType) {
+ // TODO(jmesserly): can we do something better here?
+ computedType = body.isAsynchronous ? contextType.type : _dynamicType;
+ } else {
+ computedType = contextType ?? _dynamicType;
+ }
recordInference = !computedType.isDynamic;
}
@@ -1983,8 +1989,17 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
}
}
- return ts.inferGenericFunctionCall(_typeProvider, fnType, paramTypes,
- argTypes, InferenceContext.getType(node));
+ DartType returnContext = InferenceContext.getContext(node);
+ DartType returnType;
+ if (returnContext is FutureUnionType) {
+ returnType = fnType.returnType.isDartAsyncFuture
+ ? returnContext.futureOfType
+ : returnContext.type;
+ } else {
+ returnType = returnContext as DartType;
+ }
+ return ts.inferGenericFunctionCall(
+ _typeProvider, fnType, paramTypes, argTypes, returnType);
}
return null;
}

Powered by Google App Engine
This is Rietveld 408576698