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 f68147180e5529973e12766669e0348cd963a001..c891d8aa02a2541858ac3816c9ec8e33aacfcfb0 100644 |
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart |
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart |
@@ -505,7 +505,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; |
+ TypeContext contextType = InferenceContext.getType(body); |
+ if (contextType is FutureUnionTypeContext) { |
+ // TODO(jmesserly): can we do something better here? |
+ computedType = body.isAsynchronous ? contextType.type : _dynamicType; |
+ } else { |
+ computedType = contextType ?? _dynamicType; |
+ } |
recordInference = !computedType.isDynamic; |
} |
@@ -665,7 +671,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
// If there are no type arguments and we are in strong mode, try to infer |
// some arguments. |
if (_strongMode) { |
- DartType contextType = InferenceContext.getType(node); |
+ DartType contextType = InferenceContext.getNonFutureType(node); |
// If we have a type from the context, use it. |
if (contextType is InterfaceType && |
@@ -748,7 +754,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
// If we have no explicit type arguments, and we are in strong mode |
// then try to infer type arguments. |
if (_strongMode) { |
- DartType contextType = InferenceContext.getType(node); |
+ DartType contextType = InferenceContext.getNonFutureType(node); |
// If we have a context type, use that for inference. |
if (contextType is InterfaceType && |
contextType.typeArguments.length == 2 && |
@@ -1120,7 +1126,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
} |
if (_strongMode) { |
staticType = _inferGenericInstantiationFromContext( |
- InferenceContext.getType(node), staticType); |
+ InferenceContext.getNonFutureType(node), staticType); |
} |
if (!(_strongMode && |
_inferObjectAccess(node, staticType, prefixedIdentifier))) { |
@@ -1253,7 +1259,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
} |
if (_strongMode) { |
staticType = _inferGenericInstantiationFromContext( |
- InferenceContext.getType(node), staticType); |
+ InferenceContext.getNonFutureType(node), staticType); |
} |
if (!(_strongMode && _inferObjectAccess(node, staticType, propertyName))) { |
_recordStaticType(propertyName, staticType); |
@@ -1357,7 +1363,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
} |
if (_strongMode) { |
staticType = _inferGenericInstantiationFromContext( |
- InferenceContext.getType(node), staticType); |
+ InferenceContext.getNonFutureType(node), staticType); |
} |
_recordStaticType(node, staticType); |
// TODO(brianwilkerson) I think we want to repeat the logic above using the |
@@ -1971,8 +1977,17 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
} |
} |
- return ts.inferGenericFunctionCall(_typeProvider, fnType, paramTypes, |
- argTypes, InferenceContext.getType(node)); |
+ TypeContext returnContext = InferenceContext.getType(node); |
+ DartType returnType; |
+ if (returnContext is FutureUnionTypeContext) { |
+ returnType = fnType.returnType.isDartAsyncFuture |
+ ? returnContext.futureOfType |
+ : returnContext.type; |
+ } else { |
+ returnType = returnContext as DartType; |
+ } |
+ return ts.inferGenericFunctionCall( |
+ _typeProvider, fnType, paramTypes, argTypes, returnType); |
} |
return null; |
} |