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

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 based on comments 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/lib/src/generated/type_system.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 43b0f18c908fc520c08bfa777b8ff2b629518784..6875c97011a716a9a676afb6324a97297e650397 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -504,7 +504,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;
}
@@ -1970,8 +1976,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;
}
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/lib/src/generated/type_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698