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

NS3002 false positive #118

Closed
AdamWillden opened this issue Aug 29, 2019 · 5 comments · Fixed by #119
Closed

NS3002 false positive #118

AdamWillden opened this issue Aug 29, 2019 · 5 comments · Fixed by #119
Labels
bug Something isn't working
Milestone

Comments

@AdamWillden
Copy link

        private IMapper CreateMapperMock()
        {
            var mapper = Substitute.For<IMapper>();

            mapper
                .Map<InvitationDto>(Arg.Any<Invitation>())
                .Returns(_ =>
                {
                    //  NS3002 Can not find an argument of type ... to this call
                    _invitationDto.Roles = _.Arg<Invitation>().IdentityRoles; 

                    return _invitationDto;
                });
        }
@tpodolak
Copy link
Member

Hi @AdamWillden thank you for reporting, could you show definition of IMapper interface?

@AdamWillden
Copy link
Author

@tpodolak sorry... complete lack of info from me

It is AutoMapper: https://github.com/AutoMapper/AutoMapper/blob/master/src/AutoMapper/IMapper.cs

@AdamWillden
Copy link
Author

P.S. thanks for creating this. Well worth the effort :-) and your hard work is appreciated.

@tpodolak tpodolak added the bug Something isn't working label Aug 30, 2019
@tpodolak
Copy link
Member

This bug is caused due to the way we process and compare method arguments. In your case the method is defined as

public TResult Map<TResult>(object input);

When analyzer analyses usage of _.Arg it checks the method parameters of Map definition and it sees object instead of Invitation so it reports types incompatibility.

What analyzer should do is to take parameter type from the invocation rather than from method symbol. In that case it will know that as you used Map with Invitation type and it is fine to do Arg in callback. This should be possible to fix but might be tricky to do correctly for named and optional parameters. I will try to look at this over the weekend

@AdamWillden
Copy link
Author

Fantastic, thank you again

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.

2 participants