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

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

Issue 2798663003: Fix generic function types in variable declarations (issue 29237) (Closed)
Patch Set: Created 3 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
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index ea2830a0c310c5a57327e72902da86c53332e132..5760f21810ae3dac245cd16661019fc46269cb4c 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -8461,6 +8461,38 @@ class TypeNameResolver {
DartType type = annotation.type;
if (type == null) {
return undefinedType;
+ } else if (type is FunctionType) {
+ Element element = type.element;
+ if (annotation is TypeName && element is GenericTypeAliasElement) {
+ List<TypeParameterElement> parameterElements = element.typeParameters;
+ FunctionType functionType = element.function.type;
+ if (parameterElements.isNotEmpty) {
+ List<DartType> parameterTypes =
+ TypeParameterTypeImpl.getTypes(parameterElements);
+ int parameterCount = parameterTypes.length;
+ TypeArgumentList argumentList = annotation.typeArguments;
+ List<DartType> typeArguments;
+ if (argumentList == null) {
+ typeArguments =
+ new List<DartType>.filled(parameterCount, dynamicType);
+ } else {
+ List<TypeAnnotation> arguments = argumentList.arguments;
+ int argumentCount = arguments.length;
+ if (argumentCount == parameterCount) {
+ typeArguments = new List<DartType>(parameterCount);
+ for (int i = 0; i < parameterCount; i++) {
+ typeArguments[i] = _getType(arguments[i]) ?? dynamicType;
scheglov 2017/04/05 00:11:56 Is this recursion? It seems that _getType() does n
Brian Wilkerson 2017/04/05 13:23:23 Yes, but it's guaranteed to terminate because it's
+ }
+ } else {
+ typeArguments =
+ new List<DartType>.filled(parameterCount, dynamicType);
scheglov 2017/04/05 00:11:56 Could be a bit simpler with typeArguments ??= ...f
Brian Wilkerson 2017/04/05 13:23:23 Done
+ }
+ }
+ functionType =
+ functionType.substitute2(typeArguments, parameterTypes);
+ }
+ return functionType;
+ }
}
return type;
}
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/test/generated/non_error_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698