A matcher for a `params T[]` parameter of a generic method was captured as a value. The overload that takes values was promoted with `[OverloadResolutionPriority(int.MaxValue)]`, so for `Only<T>(params T[] args)` and `Sum<T>(int level, params T[] args)` the call `Setup.Only(It.IsAny<string>())` inferred `T` as the matcher type, and with the type argument `object`, to which every matcher converts, `Verify.Only<object>(It.IsAny<object>())`, `Only<object>(It.IsAny<object[]>())`, `Only<object>(Match.AnyParameters())` and `Sum<object>(1, It.IsAny<object>())` bound the overload that takes values and matched nothing. No call could set up or verify such a method with a matcher.
A `params` array of a type parameter now blocks that promotion, as #1098 does for a parameter of type `T`: whenever a matcher overload is applicable, it outranks the overload that takes values, and it infers the type argument from the matcher.
- A lone matcher for the array matches the whole array: `Only<object>(It.IsAny<object[]>())`.
- Matchers for the elements match element by element: `Only(It.IsAny<string>())` sets up `Only<string>`, and `Only<object>(It.IsAny<object>())` matches one element. A `null` element next to them matches a `null` element, also for a nullable type argument.
- `Match.AnyParameters()` and `Match.Parameters(…)` for a lone `params T[]` stand for the parameters.
- A lone `null` for a lone `params T[]` stands for a `null` array, and a `null` for the array next to matchers for the other parameters binds the matcher for the whole array, so it does as well: `Setup.Sum<object>(It.IsAny<int>(), null)`. Above four parameters no overload combines values with the matcher for the whole array.
- A lone `null` or `default` for a parameter before such an array forwards to the overload that takes values, as #1098 does for a parameter of type `T`, so `Setup.Sum<object>(default)` stands for `Sum<object>(0)` instead of any parameters. The same holds for a non-generic sibling with a value type parameter whose all-values overload is not promoted, such as `F(int value)` beside `F<T>(T value)`, which #1098 stopped promoting, or beside `F<T>(params T[] values)`, which this change stops promoting.
- A lone `params T[]` gets the overload without arguments that `params object[]` has, so `Setup.Only<object>().AnyParameters()` keeps working, unless a sibling with as many type parameters takes a call without arguments, such as `Only<T>(T value = default!)`, which the call on the mock binds; this also holds without `OverloadResolutionPriorityAttribute`. A lone non-generic `params` array beside such a generic sibling, such as `Pick(params string[])` beside `Pick<T>(params T[])`, gets that overload as well, so `Setup.Pick().AnyParameters()` keeps working, unless a sibling with as many type parameters takes a call without arguments or another lone `params` array with as many type parameters, such as `Pick(params int[])`, would get the same overload. A lone `null` for such a non-generic array binds the `IParameters` overload, as for a lone `params T[]`, which reports CS8625 and Mockolate0006, unless the array is nullable, such as `params string?[]?`, where it forwards to the overload that takes values and throws an `ArgumentNullException`, as before.
Matchers that still bind the overload that takes values, which only happens for the type argument `object`, are recognized at runtime, as #1071 does for a parameter of type `T`: `Only<object>(It.IsAny<object>(), "a")` and `Sum<object>(1, "a", It.IsAny<object>())` match element by element and compare the plain values next to them by equality. This goes beyond `params object[]`, where a matcher next to plain values still matches nothing. A matcher for the whole array next to other elements matches one element there, as for `params object[]`. Plain values keep the comparison they had. Mockolate0007 no longer reports a matcher for an element of such an array that is recognized at runtime, as it already did not for a parameter of type `T`, and still reports a matcher for the whole array next to other elements.
```csharp
sut.Only<object>(1, "a");
sut.Only("a");
sut.Mock.Verify.Only<object>(It.IsAny<object>(), "a").Once(); // failed before
sut.Mock.Verify.Only<object>(It.IsAny<object[]>()).Once(); // failed before
sut.Mock.Verify.Only(It.IsAny<string>()).Once(); // failed before
sut.Mock.Verify.Only<object>(1, "a").Once(); // as before
```
One call behaves differently for every type argument of such a method: a `null` array now matches a `null` array instead of throwing an `ArgumentNullException`, for example `Setup.Sum<string>(1, null)` or `Verify.Only<object>(null)`, as #1031 defined it for `params object[]`. A lone `null` for a lone `params T[]` that matched any parameters, such as `Setup.Ln<object>(null)` beside `Ln<T, U>(T a = default!)`, now matches a `null` array as well. A `params` array of another element type, such as `params string[]`, still throws, unless a generic sibling stops promoting its overload that takes values: `Setup.Lk("s", null)` for `Lk(string s, params string[])` beside `Lk<T>(string s, params T[])` now matches a `null` array, and `Setup.N(null)` for `N(params string[])` beside `N<T>(params T[])` now binds the `IParameters` overload and matches any parameters instead of throwing.
This is a narrow source break, as in #1098: `.AnyParameters()` is no longer available after a matcher or a `null` for such a `params` array, or after a lone `null` or `default` or one next to such an array for another parameter (e.g. `Setup.Sum<object>(1, null).AnyParameters()` or `Setup.Sum<object>(default).AnyParameters()`), and after a `default` for a non-generic sibling with as many parameters, such as `Setup.W(1, default).AnyParameters()` for `W(int a, int b)` beside `W<T>(int a, params T[] values)`, because such a call now binds a matcher or `IParameters` overload. `Setup.K().AnyParameters()` is no longer available for `K(params string[])` beside `K<T>(params T[])` and `K(string a = "")`, because `Setup.K()` now sets up `K(string a = "")`, which the call on the mock `K()` binds, instead of a method that `K()` never calls; the same holds for a generic sibling, such as `Setup.Optional<object>().AnyParameters()` for `Optional<T>(params T[])` beside `Optional<T>(T value = default!)`. Use `Match.AnyParameters()` instead. A lone `default` that was ambiguous before can bind now: for `Ws<T>(int value)` beside `Ws<T>(params T[] values)`, `Setup.Ws<object>(default)` was CS0121 and now sets up a `null` array, as the call on the mock `Ws<object>(default)` is ambiguous as well. A lone `null` for such an array stays or becomes CS0121 beside a generic sibling with as many parameters whose last one takes a `null` as well, such as `Gm<T>(params T[][])`, `Pc<T>(params string[])` or `Pe<T>(IEnumerable<T>)`, where it did not work on main either; a sibling that takes an array of `T[]`, such as `Pn<T>(T[][])`, keeps taking it, as the call on the mock does. A lone `null` can also become ambiguous, as #1098 made it for a parameter of type `T`: for `Bo(bool value)` and `Bo(int? value)` beside `Bo<T>(params T[] values)`, `Setup.Bo(null)` is CS0121 between the matcher overloads of both siblings, whose overloads that take values are no longer promoted.
Not covered: a matcher for an element next to plain values without the type argument `object`, such as `Sum(1, It.IsAny<string>())`, which infers `T` as the matcher type, and inferring the type argument from a matcher without `OverloadResolutionPriorityAttribute`.
A matcher for a
params T[]parameter of a generic method was captured as a value. The overload that takes values was promoted with[OverloadResolutionPriority(int.MaxValue)], so forOnly<T>(params T[] args)andSum<T>(int level, params T[] args)the callSetup.Only(It.IsAny<string>())inferredTas the matcher type, and with the type argumentobject, to which every matcher converts,Verify.Only<object>(It.IsAny<object>()),Only<object>(It.IsAny<object[]>()),Only<object>(Match.AnyParameters())andSum<object>(1, It.IsAny<object>())bound the overload that takes values and matched nothing. No call could set up or verify such a method with a matcher.A
paramsarray of a type parameter now blocks that promotion, as #1098 does for a parameter of typeT: whenever a matcher overload is applicable, it outranks the overload that takes values, and it infers the type argument from the matcher.Only<object>(It.IsAny<object[]>()).Only(It.IsAny<string>())sets upOnly<string>, andOnly<object>(It.IsAny<object>())matches one element. Anullelement next to them matches anullelement, also for a nullable type argument.Match.AnyParameters()andMatch.Parameters(…)for a loneparams T[]stand for the parameters.nullfor a loneparams T[]stands for anullarray, and anullfor the array next to matchers for the other parameters binds the matcher for the whole array, so it does as well:Setup.Sum<object>(It.IsAny<int>(), null). Above four parameters no overload combines values with the matcher for the whole array.nullordefaultfor a parameter before such an array forwards to the overload that takes values, as fix: infer the type argument of a generic method from a matcher in setups and verifications #1098 does for a parameter of typeT, soSetup.Sum<object>(default)stands forSum<object>(0)instead of any parameters. The same holds for a non-generic sibling with a value type parameter whose all-values overload is not promoted, such asF(int value)besideF<T>(T value), which fix: infer the type argument of a generic method from a matcher in setups and verifications #1098 stopped promoting, or besideF<T>(params T[] values), which this change stops promoting.params T[]gets the overload without arguments thatparams object[]has, soSetup.Only<object>().AnyParameters()keeps working, unless a sibling with as many type parameters takes a call without arguments, such asOnly<T>(T value = default!), which the call on the mock binds; this also holds withoutOverloadResolutionPriorityAttribute. A lone non-genericparamsarray beside such a generic sibling, such asPick(params string[])besidePick<T>(params T[]), gets that overload as well, soSetup.Pick().AnyParameters()keeps working, unless another loneparamsarray with as many type parameters, such asPick(params int[]), would get the same overload.Matchers that still bind the overload that takes values, which only happens for the type argument
object, are recognized at runtime, as #1071 does for a parameter of typeT:Only<object>(It.IsAny<object>(), "a")andSum<object>(1, "a", It.IsAny<object>())match element by element and compare the plain values next to them by equality. This goes beyondparams object[], where a matcher next to plain values still matches nothing. A matcher for the whole array next to other elements matches one element there, as forparams object[]. Plain values keep the comparison they had. Mockolate0007 no longer reports a matcher for an element of such an array that is recognized at runtime, as it already did not for a parameter of typeT, and still reports a matcher for the whole array next to other elements.One call behaves differently for every type argument of such a method: a
nullarray now matches anullarray instead of throwing anArgumentNullException, for exampleSetup.Sum<string>(1, null)orVerify.Only<object>(null), as #1031 defined it forparams object[]. Aparamsarray of another element type, such asparams string[], still throws.This is a narrow source break, as in #1098:
.AnyParameters()is no longer available after a matcher or anullfor such aparamsarray, or after a lonenullordefaultor one next to such an array for another parameter (e.g.Setup.Sum<object>(1, null).AnyParameters()orSetup.Sum<object>(default).AnyParameters()), and after adefaultfor a non-generic sibling with as many parameters, such asSetup.W(1, default).AnyParameters()forW(int a, int b)besideW<T>(int a, params T[] values), because such a call now binds a matcher orIParametersoverload. UseMatch.AnyParameters()instead. A lonedefaultthat was ambiguous before can bind now: forWs<T>(int value)besideWs<T>(params T[] values),Setup.Ws<object>(default)was CS0121 and now sets up anullarray, as the call on the mockWs<object>(default)is ambiguous as well.Not covered: a matcher for an element next to plain values without the type argument
object, such asSum(1, It.IsAny<string>()), which infersTas the matcher type, and inferring the type argument from a matcher withoutOverloadResolutionPriorityAttribute.