GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — TUnit.Mocks: generic-method setups with explicit type arguments do not bind on Mock.Of<IGeneric<X>>() · Issue #7302 · thomhurst/TUnit

TUnit.Mocks: generic-method setups with explicit type arguments do not bind on Mock.Of<IGeneric<X>>() #7302

New issue
Copy link
New issue
Copy link
Closed
#7406
Closed
TUnit.Mocks: generic-method setups with explicit type arguments do not bind on Mock.Of<IGeneric<X>>()#7302
#7406
Copy link
Labels
P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't workingin-progressWork is in progress

Description

@thomhurst
thomhurst
opened on Oct 31, 2026
Issue body actions

Description

On a Mock<T> returned by Mock.Of<IGeneric<X>>(), a setup for a generic method fails with CS1061 when the call passes explicit method type arguments. The same call compiles on the typed wrapper that IGeneric<X>.Mock() returns. It also compiles on Mock.Of when the method type arguments can be inferred.

Found while working on #7299. It happens on main without that change, with no type parameter name collision.

Repro (TUnit.Mocks.Tests, net10.0)

Uses the existing IGenericKitchenSink<TItem, TValue> in tests/TUnit.Mocks.Tests/KitchenSinkGenericTests.cs, which declares TState RoundTrip<TState>(TState state) where TState : struct:

var mock = Mock.Of<IGenericKitchenSink<GenericPayload, int>>();
mock.RoundTrip<Guid>(Arg.Any<Guid>());   // CS1061
mock.RoundTrip(Arg.Any<Guid>());         // compiles

var wrapper = IGenericKitchenSink<GenericPayload, int>.Mock();
wrapper.RoundTrip<Guid>(Arg.Any<Guid>()); // compiles
error CS1061: 'Mock<IGenericKitchenSink<GenericPayload, int>>' does not contain a definition for 'RoundTrip' and no accessible extension method 'RoundTrip' accepting a first argument of type 'Mock<IGenericKitchenSink<GenericPayload, int>>' could be found

The generator emits the member in both extension blocks with the same shape:

extension<TItem, TValue>(global::TUnit.Mocks.Mock<global::TUnit.Mocks.Tests.IGenericKitchenSink<TItem, TValue>> mock) where TItem : class
{
    public ..._RoundTrip_M9_MockCall<TState, TItem, TValue> RoundTrip<TState>(global::TUnit.Mocks.Arguments.Arg<TState> state) where TState : struct

and

extension<TItem, TValue>(global::TUnit.Mocks.Tests.IGenericKitchenSink_TItem_TValue_Mock<TItem, TValue> mock) where TItem : class

Only the Mock<...> receiver fails to bind when explicit type arguments are present. A method whose type parameter appears only in the return type, such as T Invoke<T>(object message), therefore cannot be set up through Mock.Of<IGeneric<X>>() at all.

Expected

Mock.Of<IGeneric<X>>().Method<Y>(...) binds the same way as it does on the typed wrapper. If this is a compiler limitation of extension-block type inference, the generator should emit a shape that binds, for example a non-generic-receiver overload per closed registration, or the docs should steer users to .Mock().

Activity

  1. thomhurst
    added
    bugSomething isn't working
    P2Medium: edge case, mode divergence, flaky test, or workaround exists
    in-progressWork is in progress
    on Oct 31, 2026
  2. thomhurst
    added 6 commits that reference this issue on Nov 2, 2026

    fix(mocks): omit colliding closed setup overloads (#7302)

    9877a64

    fix(mocks): normalize closed signatures without recursive substitution (

    8741dd5

    docs(mocks): explain emitted signature collision checks (#7302)

    f46bdb2

    docs(mocks): link setup emitter to collision analysis (#7302)

    0df9256

    fix(mocks): guard closed setup analysis against emitter drift (#7302)

    360a7ca

    fix(mocks): bind explicit method type arguments on Mock.Of<IGeneric<X…

    c6f2bea
  3. thomhurst
    closed this as completedin #7406on Nov 3, 2026
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

    P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't workingin-progressWork is in progress

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.