JasonBock / Rocks

A mocking library based on the Compiler APIs (Roslyn + Mocks)
MIT License
263 stars 20 forks source link

Members That Define a Parameter With the Name `handler` Cause Issues #296

Closed JasonBock closed 10 months ago

JasonBock commented 10 months ago

To Reproduce

var code =
    """
    using Rocks;

    [assembly: RockCreate<IHandle>]

    public interface IHandle
    {
        void Handle(string handler);
    }
    """;

Expected behavior The mock is made.

Actual behavior Errors occur:

error CS0841: Cannot use local variable '@handler' before it is declared

Additional context This happens because a method or indexer defines a parameter with the name handler, and in the expectation handlers, Rocks doesn't check to ensure that name isn't used and create another one.

This was found on AngleSharp.Dom.IWindowTimers. It's recent with the code generation changes in 8.0.0.