Repository navigation
fix: match the whole array with an array matcher on a params object[] parameter - #1031
Merged
Merged
Conversation
vbreuss
enabled stacked auto-merge (squash)
November 18, 2026 15:51
vbreuss
disabled stacked auto-merge
November 18, 2026 15:53
Test Results 47 files 47 suites 1h 23m 22s ⏱️ Results for commit 543182a. ♻️ This comment has been updated with latest results. |
🚀 Benchmark ResultsCompared to Memory
Time
CompleteWorkflowBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) Intel Xeon Platinum 8370C CPU 2.80GHz (Max: 2.64GHz), 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
MockCreationBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V45 4.28GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
CompleteUnconfiguredBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) Intel Xeon 6975P-C 3.56GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
CompleteMethodBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V74 2.87GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v3 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
CompletePropertyBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V45 4.53GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
CompleteIndexerBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
CompleteEventBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V45 4.34GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
CallbackBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon) AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 11.0.100 [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
|
vbreuss
force-pushed
the
fix/params-object-array-matcher
branch
2 times, most recently
from
November 18, 2026 20:05
9a6c42c to
24c2b34
Compare
…[]` parameter
A matcher for the array of a `params object[]` parameter was captured as one element of the array. For `Log(int level, params object[] args)`, `Verify.Log(1, It.IsAny<object[]>())` bound the overload that takes values: it is promoted with `[OverloadResolutionPriority(int.MaxValue)]`, priorities are applied before the better overload is chosen, and in its expanded form it accepts any argument list, because every matcher converts to `object`. The setup or verification then expected a call with the matcher itself as argument and matched nothing. The same applied to `params dynamic[]`, `params object?[]` and a `params T[]` whose `T` is a type parameter of the mocked type that is closed over `object`.
The static type of the matcher now decides: a matcher for the array type matches the whole array, a matcher for the element type matches one element. The overloads that differ from the all-values overload only by a matcher for the `params` parameter now outrank it. With other parameters the order is `(values, IParameter<object[]>?)`, all values, `IParameters`; for a lone `params object[]` it is `IParameter<object[]>?`, `IParameters`, `params IParameter<object>[]`, all values. Nothing else moves: the overloads that replace other values by matchers stay below the all-values overload, so a `default` literal next to a `params object[]` (`Setup.Log(default, "a")`, `Setup.Log(default)`, a `default` for an optional parameter) keeps meaning the value and keeps `.AnyParameters()`.
```csharp
sut.Log(1, "a", 2);
sut.Mock.Verify.Log(1, It.IsAny<object[]>()).Once(); // failed before
sut.Mock.Verify.Log(1, "a", 2).Once(); // as before
sut.Mock.Verify.Log(It.IsAny<int>(), It.IsAny<object>(), It.Is<object>(2)).Once(); // as before
```
A lone `params object[]` needs two more things to keep the meaning of existing calls. A call without arguments would bind to the per-element overload and lose `.AnyParameters()`, so the method gets an overload without parameters (unless an overload of the method has none already): `Setup.Only()` and `Setup.Only().AnyParameters()` mean what they meant. Several `null` literals (`Setup.Only(null, null)`) now bind to the per-element overload, so its elements are nullable and a `null` matcher stands for a `null` element; the call keeps matching `Only(null, null)`.
These calls compiled before but could not work, and work now:
- `Only(Match.AnyParameters())` binds the `IParameters` overload and matches every call.
- Matchers for the elements of a lone `params object[]` match element by element: `Only(It.IsAny<object>())`, `Only(It.IsAny<string>())`, `Only(It.IsAny<object>(), It.IsAny<object>())`.
- A `null` literal for the array means a `null` array instead of throwing an `ArgumentNullException`: `Log(1, null)`, `Log(default, default)`, `Only(null)`, `Only(args: null)`.
- Next to an overload with an `object` parameter, the all-values overload of a lone `params object[]` is not promoted either, so the two compete like the methods do: for `Ov(object)` and `Ov(params object[])`, `Setup.Ov("a")`, `Setup.Ov((object)null)` and `Setup.Ov(It.IsAny<object>())` configure `Ov(object)`, which is the method that `sut.Ov("a")` calls. They configured the `params` method before.
Calls that compiled before and behave differently now:
- `.AnyParameters()` after a matcher for the array no longer compiles (CS1061), for example `Setup.Log(1, It.IsAny<object[]>()).AnyParameters()`. It only compiled because the matcher was captured as a value. This is the only call that stops compiling, and no call becomes ambiguous.
- With `.AnyParameters()`, `Setup.Ov("a").AnyParameters()` ignores the parameters of `Ov(object)` instead of those of `Ov(params object[])`, as a consequence of the last fix above.
- A `null` literal in the per-element overload of a method with other parameters (`Setup.Log(It.IsAny<int>(), null, null)`) matches `null` elements instead of nothing.
- In a group that has an overload with an `object` parameter and an overload with as many value-type parameters as the call has arguments (`M(object)`, `M(int, int)`, `M(params object[])`), `Setup.M(null, 1)` binds `M(IParameter<int>?, int)` instead of the `params` overload.
Known gaps that did not change and are tracked separately:
- A matcher for an element next to literal values binds the all-values overload and never matches: `Log(1, It.IsAny<object>())`, `Log(1, "a", It.IsAny<object>())`, `Only("a", It.IsAny<object>())`.
- Above four parameters no overload combines values with a matcher, so `Five(1, 2, 3, 4, It.IsAny<object[]>())` binds the all-values overload and never matches; these methods keep their priorities.
- A type parameter of the method is not covered: `Gen<object>(1, It.IsAny<object[]>())` on `Gen<T>(int level, params T[] args)` still binds the all-values overload.
- A `null` array that is typed as such still throws an `ArgumentNullException`: `Log(1, (object[])null)`, `Only((object[])null)`, and `Five(1, 2, 3, 4, null)` above four parameters.
A matcher for the whole array already bound correctly on delegates; their overloads did not change.
The tests compile about 200 `Setup` and `Verify` calls against the generated code, in classic and in union mode, and pin for each call the overload the compiler binds and the invocations it matches.
vbreuss
force-pushed
the
fix/params-object-array-matcher
branch
from
November 18, 2026 20:13
24c2b34 to
543182a
Compare
|
|
This is addressed in release v4.2.0. |
This was referenced Nov 19, 2026
vbreuss
added a commit
that referenced
this pull request
Nov 20, 2026
On a generic method such as `Plain<T>(T value)`, `Verify.Plain<object>(It.IsAny<object?>())` and `Setup.Plain<object>(Match.AnyParameters())` never matched. They bind the overload that takes values: it is promoted with `[OverloadResolutionPriority(int.MaxValue)]`, and once the call closes `T` over `object`, every matcher converts to the parameter, so the matcher was captured as the expected value. A declared `object` parameter avoids this because its overload that takes values is not promoted (#1031 extends that rule to `params object[]`), but a type parameter only becomes `object` at the call site. The same rule cannot be applied to type parameters. A `null` or `default` literal converts to the matcher types as well, so overload resolution cannot tell it from a matcher: without the promotion, or with the matcher overloads ranked above it, `Plain<string>(null)` and `Plain<int>(default)` would bind the `IParameters` or matcher overload and match everything or nothing, and `.AnyParameters()` after them would stop compiling. So the bindings stay as they are, and the overload that takes values recognizes a matcher at runtime. For a parameter typed with a type parameter that can be closed over `object` (no `struct`, `unmanaged`, base class or interface constraint and no `allows ref struct`), the generated setup and verification pass the value through the new `Matchers.IsValueOrMatcher`: an `IParameter<T>` is used as the matcher, an `IParameters` for the only parameter of a method as the parameters match, and any other value is compared by equality as before. These setups use `WithParameterCollection` instead of `WithLiteralValues`, and the verifications create the matcher once before counting, so matching still does not allocate. This holds for every arity, above four parameters as well, and for the overloads that mix values and matchers. ```csharp sut.Plain<object>("x"); sut.Two<object>(1, "x"); sut.Mock.Verify.Plain<object>(It.IsAny<string>()).Once(); // failed before sut.Mock.Verify.Plain<object>(Match.AnyParameters()).Once(); // failed before sut.Mock.Verify.Two<object>(1, It.IsAny<object>()).Once(); // failed before sut.Mock.Verify.Plain<object>("x").Once(); // as before ``` No call binds differently. The only change in behavior is that a matcher passed as the value of such a parameter now acts as a matcher; a non-generic `object` parameter, other type arguments and type parameters that cannot be `object` behave as before. A `params T[]` of a method type parameter (`Gen<object>(1, It.IsAny<object[]>())`) remains the known gap from #1031. Fixes #1044
vbreuss
added a commit
that referenced
this pull request
Nov 20, 2026
Methods with a `params` parameter get a per-element overload for `Setup` and `Verify`, so `It.Is(1), It.IsAny<int>()` matches the elements one by one. Delegate mocks never emitted it: on a `params T[]` delegate such a call did not compile, and on a `params object[]` delegate the element matchers bound to the overload that takes values and were compared as values, so the setup never applied and the verification never matched. The delegate emitter now adds the same overloads as the method emitter, through the same helpers and with the same priorities: the per-element overload for every arity (also above four parameters), and for a lone `params object[]` the overload without parameters that keeps `Setup().AnyParameters()` for a call without arguments. This covers the setup and verify interfaces, their implementations and the verify monitor. A `params` delegate keeps the classic overloads in union mode as well, so both modes are covered. The whole-array matcher of #1031 still matches the whole array, literal elements still match by value, and the null literals of #1032 keep their meaning; `ParamsObjectArrayTests` now compares the delegates with the methods for all of these calls, including `params string[]`. As on methods, a `null` literal for the array next to a matcher for another parameter (`Setup(It.IsAny<int>(), null)`) is now ambiguous (CS0121) between the whole-array and the per-element overload; it compiled for delegates only since #1032 and only with `OverloadResolutionPriorityAttribute`. `It.IsNull<object[]>()` expresses it unambiguously. ```csharp public delegate int Logger(int level, params object[] args); Logger logger = Logger.CreateMock(); logger.Mock.Setup(It.Is(4), It.IsAny<object>(), It.Is<object>(2)).Returns(1); int result = logger(4, "a", 2); // 1, before: 0 logger.Mock.Verify(It.Is(4), It.IsAny<object>(), It.Is<object>(2)).Once(); ``` Fixes #1045
vbreuss
added a commit
that referenced
this pull request
Nov 20, 2026
Methods with a `params` parameter get a per-element overload for `Setup` and `Verify`, so `It.Is(1), It.IsAny<int>()` matches the elements one by one. Delegate mocks never emitted it: on a `params T[]` delegate such a call did not compile, and on a `params object[]` delegate the element matchers bound to the overload that takes values and were compared as values, so the setup never applied and the verification never matched. The delegate emitter now adds the same overloads as the method emitter, through the same helpers and with the same priorities: the per-element overload for every arity (also above four parameters), and for a lone `params object[]` the overload without parameters that keeps `Setup().AnyParameters()` for a call without arguments. This covers the setup and verify interfaces, their implementations and the verify monitor, in classic and in union mode (a member with a `params` parameter always has the classic overloads). The whole-array matcher of #1031 still matches the whole array and literal elements still match by value; `ParamsObjectArrayTests` compares the delegates with the methods for these calls, including `params string[]`. Without `OverloadResolutionPriorityAttribute` (classic mode on .NET 8, .NET Framework or netstandard without a polyfill) a call without `params` arguments, such as `Setup()`, `Setup().AnyParameters()` or `Setup(It.IsAny<int>())`, would be ambiguous between the per-element overload and the one that takes the array as values. Methods already had that problem, so in that case every `params T[]` member, method or delegate, now also gets an overload that leaves out the `params` parameter and matches an empty array. With the attribute the generated code is unchanged. A failed verification with element matchers now lists them, for example `Invoke(It.IsAny<int>(), [It.IsAny<object>(), 2])`, and the overload without `params` arguments prints `[]`. The element matcher is built once per verification instead of once per recorded call. Breaking change, as on methods: on a `params T[]` delegate, a `null` array literal next to any matcher or `null` for another parameter no longer compiles (CS0121 between the whole-array and the per-element overload), for example `Setup(It.IsAny<int>(), null)`, `Setup(It.IsAny<int>(), args: null)` or `Setup(null, null)` on `(int, params object[])`. This also applies to delegates with five or more parameters, with optional parameters, or with an `object` or `int?` first parameter. Use `It.IsNull<T[]>()` for the array instead. Without `OverloadResolutionPriorityAttribute`, `null` literals for the elements are ambiguous as well (`Setup(null, null)` on a lone `params string[]`, `Setup(It.IsAny<int>(), null, null)`); pass typed values such as `(string?)null` instead. ```csharp public delegate int Logger(int level, params object[] args); Logger logger = Logger.CreateMock(); logger.Mock.Setup(It.Is(4), It.IsAny<object>(), It.Is<object>(2)).Returns(1); int result = logger(4, "a", 2); // 1, before: 0 logger.Mock.Verify(It.Is(4), It.IsAny<object>(), It.Is<object>(2)).Once(); ```
vbreuss
added a commit
that referenced
this pull request
Nov 20, 2026
On a generic method such as `Plain<T>(T value)`, `Verify.Plain<object>(It.IsAny<object?>())` and `Setup.Plain<object>(Match.AnyParameters())` never matched. They bind the overload that takes values: it is promoted with `[OverloadResolutionPriority(int.MaxValue)]`, and once the call closes `T` over `object`, every matcher converts to the parameter, so the matcher was captured as the expected value. A declared `object` parameter avoids this because its overload that takes values is not promoted (#1031 extends that rule to `params object[]`), but a type parameter only becomes `object` at the call site. The same rule cannot be applied to type parameters. A `null` or `default` literal converts to the matcher types as well, so overload resolution cannot tell it from a matcher: without the promotion, or with the matcher overloads ranked above it, `Plain<string>(null)` and `Plain<int>(default)` would bind the `IParameters` or matcher overload and match everything or nothing, and `.AnyParameters()` after them would stop compiling. So the bindings stay as they are, and the overload that takes values recognizes a matcher at runtime. For a parameter typed with a type parameter that can be closed over `object` (no `struct`, `unmanaged`, base class or interface constraint and no `allows ref struct`), the generated setup and verification pass the value through the new `Matchers.IsValueOrMatcher`: an `IParameter<T>` is used as the matcher, an `IParameters` for the only parameter of a method as the parameters match, and any other value is compared by equality as before. These setups use `WithParameterCollection` instead of `WithLiteralValues`, and the verifications create the matcher once before counting, so matching still does not allocate. This holds for every arity, above four parameters as well, and for the overloads that mix values and matchers. ```csharp sut.Plain<object>("x"); sut.Two<object>(1, "x"); sut.Mock.Verify.Plain<object>(It.IsAny<string>()).Once(); // failed before sut.Mock.Verify.Plain<object>(Match.AnyParameters()).Once(); // failed before sut.Mock.Verify.Two<object>(1, It.IsAny<object>()).Once(); // failed before sut.Mock.Verify.Plain<object>("x").Once(); // as before ``` No call binds differently. The only change in behavior is that a matcher passed as the value of such a parameter now acts as a matcher; a non-generic `object` parameter, other type arguments and type parameters that cannot be `object` behave as before. A `params T[]` of a method type parameter (`Gen<object>(1, It.IsAny<object[]>())`) remains the known gap from #1031. Fixes #1044
vbreuss
added a commit
that referenced
this pull request
Nov 20, 2026
On a generic method such as `Plain<T>(T value)`, `Verify.Plain<object>(It.IsAny<object?>())` and `Setup.Plain<object>(Match.AnyParameters())` never matched. They bind the overload that takes values: it is promoted with `[OverloadResolutionPriority(int.MaxValue)]`, and once the call closes `T` over `object`, every matcher converts to the parameter, so the matcher was captured as the expected value. A declared `object` parameter avoids this because its overload that takes values is not promoted (#1031 extends that rule to `params object[]`), but a type parameter only becomes `object` at the call site. The same rule cannot be applied to type parameters. A `null` or `default` literal converts to the matcher types as well, so overload resolution cannot tell it from a matcher: without the promotion, or with the matcher overloads ranked above it, `Plain<string>(null)` and `Plain<int>(default)` would bind the `IParameters` or matcher overload and match everything or nothing, and `.AnyParameters()` after them would stop compiling. So the bindings stay as they are, and the overload that takes values recognizes a matcher at runtime. For a parameter typed with a type parameter that can be closed over `object` (no `struct`, base class or interface constraint and no `allows ref struct`), the generated setup and verification check whether the value is an `IParameter<T>`: then it is used as the matcher (`Matchers.IsValueOrMatcher` in setups, `Matchers.AsMatcher` in verifications), and any other value is compared by equality as before. A lone parameters match, for the only parameter or next to an empty trailing `params` array, makes the overload stand in for the `IParameters` overload as a whole: the setup is a parameters setup that keeps `AnyParameters()`, and the verification matches and describes the parameters like that overload. Plain values keep the `WithLiteralValues` setup and the inline equality comparison in verifications, so they allocate no more than before; only a value that is a matcher switches to `WithParameterCollection`. This holds for every arity, above four parameters as well, and for the overloads that mix values and matchers. ```csharp sut.Plain<object>("x"); sut.Two<object>(1, "x"); sut.Log<object>("x"); sut.Mock.Verify.Plain<object>(It.IsAny<string>()).Once(); // failed before sut.Mock.Verify.Plain<object>(Match.AnyParameters()).Once(); // failed before sut.Mock.Verify.Two<object>(1, It.IsAny<object>()).Once(); // failed before sut.Mock.Verify.Log<object>(Match.AnyParameters()).Once(); // failed before, Log<T>(T value, params int[] rest) sut.Mock.Verify.Plain<object>("x").Once(); // as before ``` No call binds differently. The only change in behavior is that a matcher passed as the value of such a parameter now acts as a matcher; a non-generic `object` parameter, other type arguments and type parameters that cannot be `object` behave as before. A matcher that does not convert to the parameter type, such as `It.IsAny<int>()` for `Plain<object>`, is still a value, as for a declared `object` parameter. A `params T[]` of a method type parameter (`Gen<object>(1, It.IsAny<object[]>())`) remains the known gap from #1031.
vbreuss
added a commit
that referenced
this pull request
Nov 21, 2026
… `object` A matcher passed to a `params T[]` parameter of a generic method that the call closes over `object` was captured as a value. For `Only<T>(params T[] args)` and `Sum<T>(int level, params T[] args)`, every matcher converts to `object`, so `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, which is promoted with `[OverloadResolutionPriority(int.MaxValue)]`, and matched nothing. Before this change no call could set up or verify such a method with a matcher. The overload that takes values now recognizes the matchers at runtime, as #1071 does for a parameter of type `T`, and applies the rules of #1031 for `params object[]`: - A lone matcher for the array matches the whole array: `Only<object>(It.IsAny<object[]>())`. - Matchers for the elements match element by element, and plain values next to them are compared by equality: `Only<object>(It.IsAny<object>())`, `Sum<object>(1, "a", It.IsAny<object>())`. - A lone `Match.AnyParameters()` or `Match.Parameters(…)` for a lone `params T[]` stands for the parameters. ```csharp sut.Only<object>(1, "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<object>(1, "a").Once(); // as before ``` Plain values keep the comparison they had. A matcher that does not convert to the element type stays a value, as for a parameter of type `T`: `It.IsAny<int>()` for `Only<object>` still matches nothing. 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 `params` array of another element type, such as `params string[]`, still throws. Consumers without `OverloadResolutionPriorityAttribute` get an overload that leaves out the `params` array; it keeps matching only an empty array. Not covered, as for `params object[]`: a matcher for an element next to plain values on a method that is not generic (`Log(1, It.IsAny<object>())`), and a type argument that is inferred from the matcher (`Only(It.IsAny<string>())`).
vbreuss
added a commit
that referenced
this pull request
Nov 21, 2026
Implements #1039. Every matcher converts to `object`, so a matcher passed where `Setup` or `Verify` takes an `object` value can bind as the value itself. The setup or verification then expects a call with the matcher object as argument and silently matches nothing: ```csharp public interface IFoo { void Take(object value); void Log(int level, params object[] args); } sut.Take(5); sut.Log(1, "a", 2); sut.Mock.Verify.Take(It.IsAny<int>()).Once(); // fails: It.IsAny<int>() is no matcher for object sut.Mock.Verify.Log(1, "a", It.IsAny<object>()).Once(); // fails: no overload mixes values with element matchers ``` #1030, #1031 and #1071 already fixed the cases where a matcher for the parameter type was compared as a value. What is left cannot work as written: a matcher for another type (`It.IsAny<int>()` for an `object` parameter, property or indexer value, or indexer key), element matchers of a `params object[]` or `params T[]` next to plain values, an `object` parameter above four parameters next to plain values in classic mode, and a type argument inferred from the matcher (`Setup.Accept(It.IsAny<int>())` on `Accept<T>(T value)` infers `T` as the matcher type). The new warning Mockolate0007 reports a matcher (a type implementing `IParameter`) that binds to a value parameter of a generated `Setup` or `Verify` member, or of `Set` on a property or indexer verification. It knows the cases that work at runtime and does not report them: a matcher for the value type on a parameter typed with a type parameter that can be `object` (the same rule the generator uses for #1071), and the matcher case of a union parameter. `It.Is<object>(matcher)` and an explicit `(object)` cast are not reported, so a matcher object can still be the expected value. The message says what to change, depending on why the matcher is compared as a value: - a matcher for another type: use a matcher for the value type; - a matcher for the value type next to plain values or matchers for other types: pass matchers of the parameter types for the other arguments as well; - a type argument inferred from the matcher: state the type arguments explicitly; - a custom matcher that is also a value of the parameter type: cast it to `IParameter<T>`, or, where even that converts to the value type, that no overload takes it as a matcher. Built against the generated code of `Mockolate.Tests` in classic (net10.0) and union (net11.0) mode, every reported call fails at runtime and every call that matches is not reported. The suite itself has one hit, `DynamicMembersTests` verifying `Dyn5("a", 2, 3, 4, It.IsAny<object>())`: in classic mode the matcher is compared as a value. The test only pins the failure message, so it keeps the call with the warning suppressed. Known gaps that the rule does not report: `It.IsOut`/`It.IsRef` matchers and `Match.AnyParameters()` in a value parameter, because they are no `IParameter`. For a lone `params T[]` of a generic method closed over `object` no spelling reaches the matcher overload; the rule reports it, but fixing it needs a generator change. The descriptor lives in `MatcherAsValueAnalyzer` instead of `Rules`, like Mockolate0003 and Mockolate0006, because release tracking reports RS2002 for an unshipped rule declared in another file. The conventions and the comment in `Rules.cs` now say so for all three.
vbreuss
added a commit
that referenced
this pull request
Nov 21, 2026
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. The rules of #1031 for `params object[]` apply: - 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. - `Match.AnyParameters()` and `Match.Parameters(…)` for a lone `params T[]` stand for the parameters. - A lone `null` for a lone `params T[]` forwards to the overload that takes values, as #1098 does for a parameter of type `T`, so it stands for a `null` array. - A lone `params T[]` gets the overload without arguments that `params object[]` has, so `Setup.Only<object>().AnyParameters()` keeps working. 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. Plain values keep the comparison they had. ```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 `params` array of another element type, such as `params string[]`, still throws. This is a narrow source break, as in #1098: `.AnyParameters()` is no longer available after a matcher or a lone `null` for such a `params` array, or after a `null` or `default` literal for another parameter next to it (e.g. `Setup.Sum<object>(1, null).AnyParameters()`), because such a call now binds a matcher or `IParameters` overload. Use `Match.AnyParameters()` instead. Consumers without `OverloadResolutionPriorityAttribute` get an overload that leaves out the `params` array; it keeps matching only an empty array. Not covered, as for `params object[]`: 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.
vbreuss
added a commit
that referenced
this pull request
Nov 21, 2026
…1096) Every matcher converts to `object`, so a matcher passed where `Setup` or `Verify` takes an `object` value can bind as the value itself. The setup or verification then expects a call with the matcher object as argument and silently matches nothing: ```csharp public interface IFoo { void Take(object value); void Log(int level, params object[] args); } sut.Take(5); sut.Log(1, "a", 2); sut.Mock.Verify.Take(It.IsAny<int>()).Once(); // fails: It.IsAny<int>() is no matcher for object sut.Mock.Verify.Log(1, "a", It.IsAny<object>()).Once(); // fails: no overload mixes values with element matchers ``` #1030, #1031 and #1071 already fixed the cases where a matcher for the parameter type was compared as a value. What is left cannot work as written: a matcher for another type (`It.IsAny<int>()` for an `object` parameter, property or indexer value, or indexer key), element matchers of a `params object[]` or `params T[]` next to plain values, an `object` parameter above four parameters next to plain values in classic mode, and a type argument inferred from the matcher (`Setup.Accept(It.IsAny<int>())` on `Accept<T>(T value)` infers `T` as the matcher type). The new warning Mockolate0007 reports a matcher (a type implementing `IParameter`) that binds to a value parameter of a generated `Setup` or `Verify` member, or of `Set` on a property or indexer verification. It knows the cases that work at runtime and does not report them: a matcher for the value type on a parameter typed with a type parameter that can be `object` (the same rule the generator uses for #1071), and the matcher case of a union parameter. `It.Is<object>(matcher)` and an explicit `(object)` cast are not reported, so a matcher object can still be the expected value. The message says what to change, depending on why the matcher is compared as a value: - a matcher for another type: use a matcher for the value type; - a matcher for the value type next to plain values or matchers for other types: pass matchers of the parameter types for the other arguments as well; - a type argument inferred from the matcher: state the type arguments explicitly; - a custom matcher that is also a value of the parameter type: cast it to `IParameter<T>`, or, where even that converts to the value type, that no overload takes it as a matcher. Built against the generated code of `Mockolate.Tests` in classic (net10.0) and union (net11.0) mode, every reported call fails at runtime and every call that matches is not reported. The suite itself has one hit, `DynamicMembersTests` verifying `Dyn5("a", 2, 3, 4, It.IsAny<object>())`: in classic mode the matcher is compared as a value. The test only pins the failure message, so it keeps the call with the warning suppressed. Known gaps that the rule does not report: `It.IsOut`/`It.IsRef` matchers and `Match.AnyParameters()` in a value parameter, because they are no `IParameter`. For a lone `params T[]` of a generic method closed over `object` no spelling reaches the matcher overload; the rule reports it, but fixing it needs a generator change. The descriptor lives in `MatcherAsValueAnalyzer` instead of `Rules`, like Mockolate0003 and Mockolate0006, because release tracking reports RS2002 for an unshipped rule declared in another file. The conventions and the comment in `Rules.cs` now say so for all three.
vbreuss
added a commit
that referenced
this pull request
Nov 21, 2026
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, and a lone `null` for it forwards to the overload that takes values. 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 `params` array of another element type, such as `params string[]`, still throws. 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. 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. 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`.
vbreuss
added a commit
that referenced
this pull request
Nov 21, 2026
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, and a lone `null` for it forwards to the overload that takes values. 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 `params` array of another element type, such as `params string[]`, still throws. 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. 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. 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`.
vbreuss
added a commit
that referenced
this pull request
Nov 21, 2026
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 another lone `params` array with as many type parameters, such as `Pick(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 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 `params` array of another element type, such as `params string[]`, still throws. 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. 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. 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`.
vbreuss
added a commit
that referenced
this pull request
Nov 21, 2026
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 keeps binding the `IParameters` overload, which reports CS8625 and Mockolate0006, unless the array is nullable, such as `params string?[]?`, where it forwards to the overload that takes values, as the call on the mock takes a lone `null` as well. 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 `params` array of another element type, such as `params string[]`, still throws. 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. 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` can 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`.
vbreuss
added a commit
that referenced
this pull request
Nov 22, 2026
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 keeps binding the `IParameters` overload, 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 `params` array of another element type, such as `params string[]`, still throws. 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. 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` can 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`.
vbreuss
added a commit
that referenced
this pull request
Nov 22, 2026
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` can 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`.
vbreuss
added a commit
that referenced
this pull request
Nov 22, 2026
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`.
vbreuss
added a commit
that referenced
this pull request
Nov 22, 2026
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 that takes a `params` array or another reference type in that place, such as `Gm<T>(params T[][])`, `Pc<T>(params string[])` or `Pe<T>(IEnumerable<T>)`, where it did not work on main either or the call on the mock is ambiguous as well; a sibling that takes an array there, such as `Pn<T>(T[][])` or `Za<T>(string[])`, 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`.
vbreuss
added a commit
that referenced
this pull request
Nov 22, 2026
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)`, unless a sibling with as many parameters may take a `null` in that place. 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 `null` for such an array stays or becomes CS0121 beside a sibling with as many parameters that may take a `null` in that place, instead of binding a method that the call on the mock may not bind. It did not work on main beside `Gm<T>(params T[][])`, `Pc<T>(params string[])` or `Pe<T>(IEnumerable<T>)` either, but on main `Setup.Za<object>(null)` for `Za<T>(string[] a)` beside `Za<T>(params T[] args)` and `Setup.Ya<object>(null, null)` for `Ya<T>(string x, string y)` beside `Ya<T>(int level, params T[] args)` set up the sibling, and `.AnyParameters()` was available after them. Only a sibling that takes an array of `T[]` there, such as `Pn<T>(T[][])`, keeps taking a `null`, 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`.
vbreuss
added a commit
that referenced
this pull request
Nov 22, 2026
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. For a method without overloads, 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 method with overloads keeps the promotion and binds as before, because each same-named overload competes with an unpromoted overload in ways that the call on the mock does not, and would capture calls such as `Setup.Add(1, 2)` for `Add(double a, double b)` beside `Add<T>(params T[] values)`, which the call on the mock `Add(1, 2)` binds to `Add<int>`. - 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. - A lone `params T[]` gets the overload without arguments that `params object[]` has, so `Setup.Only<object>().AnyParameters()` keeps working. Matchers that still bind the overload that takes values, which only happens for the type argument `object`, also on a method with overloads, are recognized at runtime, as #1071 does for a parameter of type `T`: `Only<object>(It.IsAny<object>(), "a")`, `Sum<object>(1, "a", It.IsAny<object>())` and `Add<object>("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 without overloads: 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[]`. This is a narrow source break for a method without overloads, 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()`), because such a call now binds a matcher or `IParameters` overload. Use `Match.AnyParameters()` instead. 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; a method with overloads, where matchers without a type argument still infer `T` as the matcher type, as in `Setup.Add(It.IsAny<int>(), It.IsAny<int>())`, and need it, as in `Setup.Add<int>(It.IsAny<int>(), It.IsAny<int>())`; and inferring the type argument from a matcher without `OverloadResolutionPriorityAttribute`.
vbreuss
added a commit
that referenced
this pull request
Nov 22, 2026
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. Only calls with a matcher for every parameter worked. For a method without overloads or optional parameters, 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 method with overloads keeps the promotion and binds as before, because each same-named overload competes with an unpromoted overload in ways that the call on the mock does not, and would capture calls such as `Setup.Add(1, 2)` for `Add(double a, double b)` beside `Add<T>(params T[] values)`, which the call on the mock `Add(1, 2)` binds to `Add<int>`. An optional parameter before the array keeps it as well, because an overload for matchers takes a `null` for it as its declared default value, so `Setup.Opt<object>(1, null)` for `Opt<T>(int a, string? s = "x", params T[] args)` would set up `s = "x"` instead of `s = null`. - 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. - A lone `params T[]` gets the overload without arguments that `params object[]` has, so `Setup.Only<object>().AnyParameters()` keeps working. Matchers that still bind the overload that takes values, which only happens for the type argument `object`, also on a method with overloads, are recognized at runtime, as #1071 does for a parameter of type `T`: `Only<object>(It.IsAny<object>(), "a")`, `Sum<object>(1, "a", It.IsAny<object>())` and `Add<object>("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, now saying that it only matches the array as its only element. ```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 ``` Two kinds of calls behave differently. A `null` array now matches a `null` array instead of throwing an `ArgumentNullException`, as #1031 defined it for `params object[]`, for every type argument, for example `Setup.Sum<string>(1, null)` or `Verify.Only<object>(null)`, and also on a method with overloads or optional parameters, where the call binds the overload that takes values as before, such as `Setup.Add<string>(null!)`. A `null` element for a value type now stands for its default value, as a `null` does for a value type parameter, so `Setup.Sum<int>(default, default, default)` and `Verify.Only<int>(It.IsAny<int>(), default)` match zeros instead of nothing; this holds for every per-element overload of a `params` array of a value type. This is a narrow source break for a method without overloads or optional parameters, 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()`), because such a call now binds a matcher or `IParameters` overload. Use `Match.AnyParameters()` instead. 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; a method with overloads, where matchers without a type argument still infer `T` as the matcher type, as in `Setup.Add(It.IsAny<int>(), It.IsAny<int>())`, and need it, as in `Setup.Add<int>(It.IsAny<int>(), It.IsAny<int>())`; and inferring the type argument from a matcher without `OverloadResolutionPriorityAttribute`.
vbreuss
added a commit
that referenced
this pull request
Nov 22, 2026
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. Only calls with a matcher for every parameter worked. For a method without overloads or optional parameters, 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 method with overloads keeps the promotion and binds as before, because each same-named overload competes with an unpromoted overload in ways that the call on the mock does not, and would capture calls such as `Setup.Add(1, 2)` for `Add(double a, double b)` beside `Add<T>(params T[] values)`, which the call on the mock `Add(1, 2)` binds to `Add<int>`. An optional parameter before the array keeps it as well, because an overload for matchers takes a `null` for it as its declared default value, so `Setup.Opt<object>(1, null)` for `Opt<T>(int a, string? s = "x", params T[] args)` would set up `s = "x"` instead of `s = null`. - 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. - A lone `params T[]` gets the overload without arguments that `params object[]` has, so `Setup.Only<object>().AnyParameters()` keeps working. Matchers that still bind the overload that takes values, which only happens for the type argument `object`, also on a method with overloads, are recognized at runtime, as #1071 does for a parameter of type `T`: `Only<object>(It.IsAny<object>(), "a")`, `Sum<object>(1, "a", It.IsAny<object>())` and `Add<object>("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, now saying that it only matches the array as its only element. ```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 ``` Two kinds of calls behave differently. A `null` array now matches a `null` array instead of throwing an `ArgumentNullException`, as #1031 defined it for `params object[]`, for every type argument, for example `Setup.Sum<string>(1, null)` or `Verify.Only<object>(null)`, and also on a method with overloads or optional parameters, where the call binds the overload that takes values as before, such as `Setup.Add<string>(null!)`. A `null` element for a value type now stands for its default value, as a `null` does for a value type parameter, so `Setup.Sum<int>(default, default, default)` and `Verify.Only<int>(It.IsAny<int>(), default)` match zeros instead of nothing; this holds for every per-element overload of a `params` array of a value type. This is a narrow source break for a method without overloads or optional parameters, 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()`), because such a call now binds a matcher or `IParameters` overload. Use `Match.AnyParameters()` instead. 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; a method with overloads, where matchers without a type argument still infer `T` as the matcher type, as in `Setup.Add(It.IsAny<int>(), It.IsAny<int>())`, and need it, as in `Setup.Add<int>(It.IsAny<int>(), It.IsAny<int>())`; and inferring the type argument from a matcher without `OverloadResolutionPriorityAttribute`.
vbreuss
added a commit
that referenced
this pull request
Nov 22, 2026
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 another lone `params` array with as many type parameters, such as `Pick(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 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 `params` array of another element type, such as `params string[]`, still throws. 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. 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.
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



A matcher for the array type on a
params object[](orparams dynamic[]) parameter was captured as a single element instead of matching the whole array, so the setup or verification never matched a real call:The overload that takes a value for every parameter is promoted with
OverloadResolutionPriority(int.MaxValue). With aparams object[]it accepts any argument list in its expanded form, because every matcher converts toobject, so it outranked the overload that takes the array matcher. A plainobjectparameter has the same hazard and already skips the promotion (ParametersBlockAllValuesPromotion); aparams object[]value parameter now skips it as well. The matcher overloads then win whenever they apply, and the all-values overload still binds literal elements such asLog(1, "a", 2)and an explicitobject[], because no other overload accepts them.The static type of the matcher decides between the two readings of a single matcher argument:
It.IsAny<object[]>()(the array type) matches the whole array,It.IsAny<object>()(the element type) matches one element.For a method whose only parameter is a
params object[], a lonenullnow reaches theIParametersoverload, like it does for a singleobjectparameter. It is forwarded as anullmatcher for the array, soOnly(null)matches a call with anullarray (it threw anArgumentNullExceptionbefore). On such a method,Only()now binds to the per-element matcher overload with no elements: it still matches only calls without arguments, but no longer offers.AnyParameters().Other
paramselement types and indexers are not affected. Delegates already bound correctly, because their value overloads carry no priorities.