nsubstitute / NSubstitute.Analyzers

Roslyn analysers for NSubstitute.
MIT License
30 stars 7 forks source link

NS3005: Could not set argument. #223

Open voroninp opened 2 months ago

voroninp commented 2 months ago

Describe the bug I am aware about Arg,Do<TArg>(...) api, but I am curious why I see this analzyer warning:

NS3005:Could not set argument.

This yields a warning: image

But this does not: image

To Reproduce

TimerCallback? cb = null;
object? state = null;
var timer = Substitute.For<ITimer>();
var timeProvider = Substitute.For<TimeProvider>();
timeProvider.CreateTimer(Arg.Any<TimerCallback>(), Arg.Any<object?>(), Arg.Any<TimeSpan>(), Arg.Any<TimeSpan>())
    .Returns(timer)
    .AndDoes(ci =>
    {
        cb = ci[0] as TimerCallback;
        state = ci[1];
    });

Expected behaviour There should not any warning here.

Environment:

dtchepak commented 2 months ago

Hi @voroninp ,

Thanks for raising this. I've transferred it to the Analyzers project which is detecting NS3005.

cc: @tpodolak

tpodolak commented 1 month ago

@voroninp thanks for reporting. It loosk like analyzer confues

 state = ci[1];

with

c[1] = state