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 cc8e2f06e5ca9c4f409d14c684c20f332974cef1..c487796cbbda23609768132559c765cebfdeeb75 100644 |
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart |
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart |
@@ -510,7 +510,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
@override |
Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
if (_strongMode) { |
- _inferFunctionInvocationGeneric(node); |
+ _inferGenericInvoke(node); |
} |
DartType staticType = _computeInvokeReturnType(node.staticInvokeType); |
_recordStaticType(node, staticType); |
@@ -742,7 +742,7 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
SimpleIdentifier methodNameNode = node.methodName; |
Element staticMethodElement = methodNameNode.staticElement; |
if (_strongMode) { |
- _inferMethodInvocationGeneric(node); |
+ _inferGenericInvoke(node); |
} |
// Record types of the variable invoked as a function. |
if (staticMethodElement is VariableElement) { |
@@ -1815,26 +1815,6 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
} |
/** |
- * Similar to [_inferMethodInvocationGeneric] but for function expression |
- * invocations. |
- */ |
- // TODO(jmesserly): if we had a common AST interface between these two nodes, |
- // we could remove this duplicated code. |
- bool _inferFunctionInvocationGeneric(FunctionExpressionInvocation node) { |
- DartType instantiatedType = node.staticInvokeType; |
- DartType originalType = node.function.staticType; |
- if (instantiatedType is FunctionType && originalType is FunctionType) { |
- FunctionType inferred = _inferGenericInvoke(instantiatedType, |
- originalType, node.typeArguments, node.argumentList); |
- if (inferred != null) { |
- node.staticInvokeType = inferred; |
- return true; |
- } |
- } |
- return false; |
- } |
- |
- /** |
* Given an uninstantiated generic type, try to infer the instantiated generic |
* type from the surrounding context. |
*/ |
@@ -1849,41 +1829,42 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
return type; |
} |
- FunctionType _inferGenericInvoke(FunctionType invokeType, FunctionType fnType, |
- TypeArgumentList typeArguments, ArgumentList argumentList) { |
+ bool _inferGenericInvoke(InvocationExpression node) { |
TypeSystem ts = _typeSystem; |
- if (typeArguments == null && ts is StrongTypeSystemImpl) { |
- if (fnType.typeFormals.isNotEmpty && |
- ts.instantiateToBounds(fnType) == invokeType) { |
- // Get the parameters that correspond to the uninstantiated generic. |
- List<ParameterElement> rawParameters = |
- ResolverVisitor.resolveArgumentsToParameters( |
- argumentList, fnType.parameters, null); |
- |
- List<DartType> paramTypes = <DartType>[]; |
- List<DartType> argTypes = <DartType>[]; |
- for (int i = 0, length = rawParameters.length; i < length; i++) { |
- ParameterElement parameter = rawParameters[i]; |
- if (parameter != null) { |
- paramTypes.add(parameter.type); |
- argTypes.add(argumentList.arguments[i].staticType); |
- } |
+ DartType fnType = node.function.staticType; |
+ if (node.typeArguments == null && |
+ fnType is FunctionType && |
+ fnType.typeFormals.isNotEmpty && |
+ ts is StrongTypeSystemImpl) { |
+ ArgumentList argumentList = node.argumentList; |
+ // Get the parameters that correspond to the uninstantiated generic. |
+ List<ParameterElement> rawParameters = ResolverVisitor |
+ .resolveArgumentsToParameters(argumentList, fnType.parameters, null); |
+ |
+ List<DartType> paramTypes = <DartType>[]; |
+ List<DartType> argTypes = <DartType>[]; |
+ for (int i = 0, length = rawParameters.length; i < length; i++) { |
+ ParameterElement parameter = rawParameters[i]; |
+ if (parameter != null) { |
+ paramTypes.add(parameter.type); |
+ argTypes.add(argumentList.arguments[i].staticType); |
} |
+ } |
- FunctionType inferred = ts.inferCallFromArguments( |
- _typeProvider, fnType, paramTypes, argTypes); |
+ FunctionType inferred = ts.inferGenericFunctionCall(_typeProvider, fnType, |
+ paramTypes, argTypes, InferenceContext.getType(node)); |
- if (inferred != fnType) { |
- // Fix up the parameter elements based on inferred method. |
- List<ParameterElement> inferredParameters = |
- ResolverVisitor.resolveArgumentsToParameters( |
- argumentList, inferred.parameters, null); |
- argumentList.correspondingStaticParameters = inferredParameters; |
- return inferred; |
- } |
+ if (inferred != node.staticInvokeType) { |
+ // Fix up the parameter elements based on inferred method. |
+ List<ParameterElement> inferredParameters = |
+ ResolverVisitor.resolveArgumentsToParameters( |
+ argumentList, inferred.parameters, null); |
+ argumentList.correspondingStaticParameters = inferredParameters; |
+ node.staticInvokeType = inferred; |
+ return true; |
} |
} |
- return null; |
+ return false; |
} |
/** |
@@ -1906,27 +1887,6 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> { |
} |
/** |
- * Given a generic method invocation [node], attempt to infer the method's |
- * type variables, using the actual types of the arguments. |
- */ |
- bool _inferMethodInvocationGeneric(MethodInvocation node) { |
- DartType instantiatedType = node.staticInvokeType; |
- DartType originalType = node.methodName.staticType; |
- // TODO(jmesserly): support generic `call` methods. |
- // Perhaps we should always record a FunctionType in staticInvokeType |
- // and the methodName's staticType. |
- if (instantiatedType is FunctionType && originalType is FunctionType) { |
- FunctionType inferred = _inferGenericInvoke(instantiatedType, |
- originalType, node.typeArguments, node.argumentList); |
- if (inferred != null) { |
- node.staticInvokeType = inferred; |
- return true; |
- } |
- } |
- return false; |
- } |
- |
- /** |
* Given a method invocation [node], attempt to infer a better |
* type for the result if it is an inline JS invocation |
*/ |