instantiate method
Creates a new function type by instantiating this generic function with the provided type arguments.
Implementation
FunctionType instantiate(List<DartType> argumentTypes) {
if (argumentTypes.length != typeParameters.length) {
throw ArgumentError(
"argumentTypes.length (${argumentTypes.length}) != "
"typeParameters.length (${typeParameters.length})",
);
}
if (argumentTypes.isEmpty) {
return this;
}
Substitution substitution = Substitution.fromPairs(
typeParameters,
argumentTypes,
);
final List<ParameterElement> newParams = List<ParameterElement>.of(
parameters,
);
for (final ParameterElementImpl param in parameters.whereType<ParameterElementImpl>()) {
param.type = substitution.substituteType(param.type);
}
return FunctionType(
returnType: substitution.substituteType(returnType),
typeParameters: const <TypeParameterType>[],
parameters: newParams,
isNullable: isNullable,
);
}