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

Unified Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 1874123002: Infer generic method invocation type. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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/summary/link.dart
diff --git a/pkg/analyzer/lib/src/summary/link.dart b/pkg/analyzer/lib/src/summary/link.dart
index 9805659ea59e623b4fccbaf2ecc2b17e128b2f58..cf1f1ecd3a2d84b03ce1ffe4943038bc93eedf9f 100644
--- a/pkg/analyzer/lib/src/summary/link.dart
+++ b/pkg/analyzer/lib/src/summary/link.dart
@@ -3244,16 +3244,51 @@ class TypeInferenceNode extends Node<TypeInferenceNode> {
stack.add(DynamicTypeImpl.instance);
break;
case UnlinkedConstOperation.invokeMethod:
- strPtr++;
int numNamed = unlinkedConst.ints[intPtr++];
int numPositional = unlinkedConst.ints[intPtr++];
- // TODO(paulberry): don't just pop the args; use their types
- // to infer the type of type arguments.
- stack.length -= numNamed + numPositional;
- strPtr += numNamed;
- stack.removeLast();
- // TODO(paulberry): implement.
- stack.add(DynamicTypeImpl.instance);
+ Map<String, DartType> namedArgTypes = <String, DartType>{};
+ List<DartType> namedArgTypeList = popList(numNamed);
+ for (int i = 0; i < numNamed; i++) {
+ String name = unlinkedConst.strings[strPtr++];
+ DartType type = namedArgTypeList[i];
+ namedArgTypes[name] = type;
+ }
+ List<DartType> positionalArgTypes = popList(numPositional);
+ String methodName = unlinkedConst.strings[strPtr++];
+ DartType target = stack.removeLast();
+ stack.add(() {
+ if (target is InterfaceType) {
+ MethodElement method =
+ target.lookUpMethod(methodName, libraryElement);
+ DartType rawMethodType = method?.type;
+ TypeSystem ts = linker.typeSystem;
+ if (rawMethodType is FunctionType &&
+ rawMethodType.typeFormals.isNotEmpty &&
Paul Berry 2016/04/09 12:04:29 This means we won't handle non-generic cases. Sug
scheglov 2016/04/10 01:29:21 Thank you, fixed.
+ ts is StrongTypeSystemImpl) {
+ List<DartType> paramTypes = <DartType>[];
+ List<DartType> argTypes = <DartType>[];
+ for (int i = 0, length = numPositional; i < length; i++) {
+ ParameterElement parameter = rawMethodType.parameters[i];
+ if (parameter != null) {
+ paramTypes.add(parameter.type);
+ argTypes.add(positionalArgTypes[i]);
+ }
+ }
+ Map<String, DartType> namedParameterTypes = rawMethodType.namedParameterTypes;
+ namedArgTypes.forEach((String name, DartType argType) {
+ DartType parameterType = namedParameterTypes[name];
+ if (parameterType != null) {
+ paramTypes.add(parameterType);
+ argTypes.add(argType);
+ }
+ });
+ FunctionType inferred = ts.inferGenericFunctionCall(
+ typeProvider, rawMethodType, paramTypes, argTypes, null);
+ return inferred.returnType;
+ }
+ }
+ return DynamicTypeImpl.instance;
+ }());
break;
case UnlinkedConstOperation.cascadeSectionBegin:
stack.add(stack.last);
« 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