Skip to content

Mock setup extensions fail to compile for parameters named matchers or mock #7657

Closed

Description

@thomhurst

Summary

Mocking an interface whose method has a parameter named matchers or mock produces conflicting identifiers in generated setup extensions. Valid interface parameter names should compile with Mock.Of<T>().

Reproduction

In a project using TUnit.Mocks, define:

public interface IService
{
    void Send(string matchers);
    void Receive(string mock);
}

Generate a mock with Mock.Of<IService>() and build.

Expected and actual

Expected: generated setup extensions use distinct identifiers and compile.
Actual: setup extensions copy parameter names but also declare a local matchers and a receiver parameter mock, causing duplicate declarations. The predicate-local allocator in #7655 addresses a separate collision and does not fix these fixed names.

Environment

Observed in generated setup extensions at commit 07f7cd9, src/TUnit.Mocks.SourceGenerator/Builders/MockMembersBuilder.cs, in review of #7655. The checked-in snapshot in that PR shows the fixed receiver and local declarations.

Please allocate generated receiver and local names without colliding with source parameter names, with compilation regression coverage.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions