in lib/src/mock.dart [347:399]
static List<dynamic> _reconstitutePositionalArgs(Invocation invocation) {
final positionalArguments = <dynamic>[];
final nullPositionalArguments =
invocation.positionalArguments.where((arg) => arg == null);
if (_storedArgs.length > nullPositionalArguments.length) {
// More _positional_ ArgMatchers were stored than were actually passed as
// positional arguments. There are three ways this call could have been
// parsed and resolved:
//
// * an ArgMatcher was passed in [invocation] as a named argument, but
// without a name, and thus stored in [_storedArgs], something like
// `when(obj.fn(a: any))`,
// * an ArgMatcher was passed in an expression which was passed in
// [invocation], and thus stored in [_storedArgs], something like
// `when(obj.fn(Foo(any)))`, or
// * a combination of the above.
_storedArgs.clear();
_storedNamedArgs.clear();
throw ArgumentError(
'An argument matcher (like `any`) was either not used as an '
'immediate argument to ${invocation.memberName} (argument matchers '
'can only be used as an argument for the very method being stubbed '
'or verified), or was used as a named argument without the Mockito '
'"named" API (Each argument matcher that is used as a named argument '
'needs to specify the name of the argument it is being used in. For '
'example: `when(obj.fn(x: anyNamed("x")))`).');
}
var storedIndex = 0;
var positionalIndex = 0;
while (storedIndex < _storedArgs.length &&
positionalIndex < invocation.positionalArguments.length) {
var arg = _storedArgs[storedIndex];
if (invocation.positionalArguments[positionalIndex] == null) {
// Add the [ArgMatcher] given to the argument matching helper.
positionalArguments.add(arg);
storedIndex++;
positionalIndex++;
} else {
// An argument matching helper was not used; add the [ArgMatcher] from
// [invocation].
positionalArguments
.add(invocation.positionalArguments[positionalIndex]);
positionalIndex++;
}
}
while (positionalIndex < invocation.positionalArguments.length) {
// Some trailing non-ArgMatcher arguments.
positionalArguments.add(invocation.positionalArguments[positionalIndex]);
positionalIndex++;
}
return positionalArguments;
}