@@ -1312,17 +1312,16 @@ class ClassElementImpl extends AbstractClassElementImpl
13121312 // to produce constructors for this class. We want to be robust in the
13131313 // face of errors, so drop any extra type arguments and fill in any missing
13141314 // ones with `dynamic`.
1315- var superTypeParameters = supertype.typeParameters;
1315+ List <DartType > parameterTypes =
1316+ TypeParameterTypeImpl .getTypes (supertype.typeParameters);
13161317 List <DartType > argumentTypes = new List <DartType >.filled (
1317- superTypeParameters .length, DynamicTypeImpl .instance);
1318+ parameterTypes .length, DynamicTypeImpl .instance);
13181319 for (int i = 0 ; i < supertype.typeArguments.length; i++ ) {
13191320 if (i >= argumentTypes.length) {
13201321 break ;
13211322 }
13221323 argumentTypes[i] = supertype.typeArguments[i];
13231324 }
1324- var substitution =
1325- Substitution .fromPairs (superTypeParameters, argumentTypes);
13261325
13271326 // Now create an implicit constructor for every constructor found above,
13281327 // substituting type parameters as appropriate.
@@ -1354,7 +1353,7 @@ class ClassElementImpl extends AbstractClassElementImpl
13541353 implicitParameter.parameterKind = superParameter.parameterKind;
13551354 implicitParameter.isSynthetic = true ;
13561355 implicitParameter.type =
1357- substitution. substituteType ( superParameter.type);
1356+ superParameter.type. substitute2 (argumentTypes, parameterTypes );
13581357 implicitParameters[i] = implicitParameter;
13591358 }
13601359 implicitConstructor.parameters = implicitParameters;
@@ -6444,33 +6443,18 @@ class GenericTypeAliasElementImpl extends ElementImpl
64446443
64456444 @override
64466445 FunctionType instantiate (List <DartType > argumentTypes) {
6447- return instantiate2 (
6448- typeArguments: argumentTypes,
6449- nullabilitySuffix: NullabilitySuffix .star,
6450- );
6446+ return doInstantiate (this , argumentTypes);
64516447 }
64526448
64536449 @override
64546450 FunctionType instantiate2 ({
64556451 @required List <DartType > typeArguments,
64566452 @required NullabilitySuffix nullabilitySuffix,
64576453 }) {
6458- if (function == null ) {
6459- return null ;
6460- }
6461-
6462- if (typeArguments.length != typeParameters.length) {
6463- throw new ArgumentError (
6464- "typeArguments.length (${typeArguments .length }) != "
6465- "typeParameters.length (${typeParameters .length })" );
6466- }
6467-
6468- var substitution = Substitution .fromPairs (typeParameters, typeArguments);
6469- var type = substitution.substituteType (function.type) as FunctionType ;
64706454 return FunctionTypeImpl .synthetic (
6471- type. returnType,
6472- type.typeFormals ,
6473- type. parameters,
6455+ returnType,
6456+ typeParameters ,
6457+ parameters,
64746458 element: this ,
64756459 typeArguments: typeArguments,
64766460 nullabilitySuffix: nullabilitySuffix,
@@ -6483,6 +6467,47 @@ class GenericTypeAliasElementImpl extends ElementImpl
64836467 safelyVisitChildren (typeParameters, visitor);
64846468 function? .accept (visitor);
64856469 }
6470+
6471+ static FunctionType doInstantiate (
6472+ FunctionTypeAliasElement element, List <DartType > argumentTypes) {
6473+ if (argumentTypes.length != element.typeParameters.length) {
6474+ throw new ArgumentError ('Wrong number of type arguments supplied' );
6475+ }
6476+ if (element.typeParameters.isEmpty) return element.function.type;
6477+ return typeAfterSubstitution (element, argumentTypes);
6478+ }
6479+
6480+ /// Return the type of the function defined by this typedef after substituting
6481+ /// the given [typeArguments] for the type parameters defined for this typedef
6482+ /// (but not the type parameters defined by the function). If the number of
6483+ /// [typeArguments] does not match the number of type parameters, then
6484+ /// `dynamic` will be used in place of each of the type arguments.
6485+ static FunctionType typeAfterSubstitution (
6486+ FunctionTypeAliasElement element, List <DartType > typeArguments) {
6487+ GenericFunctionTypeElement function = element.function;
6488+ if (function == null ) {
6489+ return null ;
6490+ }
6491+ FunctionType functionType = function.type;
6492+
6493+ List <TypeParameterElement > parameterElements = element.typeParameters;
6494+ int parameterCount = parameterElements.length;
6495+
6496+ if (typeArguments == null ||
6497+ parameterElements.length != typeArguments.length) {
6498+ DartType dynamicType = element.context.typeProvider.dynamicType;
6499+ typeArguments = new List <DartType >.filled (parameterCount, dynamicType);
6500+ }
6501+
6502+ if (element is GenericTypeAliasElementImpl && element.linkedNode != null ) {
6503+ return Substitution .fromPairs (parameterElements, typeArguments)
6504+ .substituteType (functionType);
6505+ }
6506+
6507+ List <DartType > parameterTypes =
6508+ TypeParameterTypeImpl .getTypes (parameterElements);
6509+ return functionType.substitute2 (typeArguments, parameterTypes);
6510+ }
64866511}
64876512
64886513/// A concrete implementation of a [HideElementCombinator] .
0 commit comments