Skip to content

Delegates with a params parameter have no per-element matcher overload #1045

Closed

Description

@vbreuss

Sources.MockDelegate.cs never emits the per-element overload. For params object[] the only applicable delegate overload is (IParameter<int>?, params object[]), so element matchers are captured as array elements and compared as values:

public interface ILog { int Invoke(int level, params object[] args); }
public delegate int Logger(int level, params object[] args);

// method: the setup returns its value, the verification passes
log.Mock.Setup.Invoke(It.Is(4), It.IsAny<object>(), It.Is<object>(2)).Returns(1);

// delegate: compiles, never matches
logger.Mock.Setup(It.Is(4), It.IsAny<object>(), It.Is<object>(2)).Returns(1);
logger.Mock.Verify(It.Is(4), It.IsAny<object>(), It.Is<object>(2)).Once();
// Expected that mock invoked method Invoke(4, System.Object[]) exactly once, but it never did.

Every other shape behaves the same on delegates and methods (pinned by ParamsObjectArray_InClassicMode_OnDelegates_ShouldBindLikeMethods and the union variant in Tests/Mockolate.SourceGenerators.Tests/ParamsObjectArrayTests.cs on that branch): whole-array matcher, literal elements, null, a single params parameter, Match.AnyParameters(). That test leaves this shape out.

Check first: what the same call does for params int[] / params string[] on a delegate (expected: a compile error, since a matcher is not an element), and for a delegate whose only parameter is params.

Activity

  1. added theissue type on Nov 18, 2026
  2. added a commit that references this issue on Nov 20, 2026
    3bf9638
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions