Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NS3005: Could not set argument. #223

Open
voroninp opened this issue Jul 3, 2024 · 2 comments · May be fixed by #224
Open

NS3005: Could not set argument. #223

voroninp opened this issue Jul 3, 2024 · 2 comments · May be fixed by #224
Labels
bug Something isn't working

Comments

@voroninp
Copy link

voroninp commented Jul 3, 2024

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:

  • NSubstitute version: 5.1.0
  • NSubstitute.Analyzers version: CSharp 1.0.17
  • Platform: [.net 8 on Windows]
@dtchepak dtchepak transferred this issue from nsubstitute/NSubstitute Jul 7, 2024
@dtchepak
Copy link
Member

dtchepak commented Jul 7, 2024

Hi @voroninp ,

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

cc: @tpodolak

@tpodolak tpodolak added the bug Something isn't working label Jul 21, 2024
@tpodolak
Copy link
Member

@voroninp thanks for reporting. It loosk like analyzer confues

 state = ci[1];

with

c[1] = state

tpodolak added a commit that referenced this issue Jul 22, 2024
@tpodolak tpodolak linked a pull request Jul 22, 2024 that will close this issue
tpodolak added a commit that referenced this issue Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants