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

Non-Virtual Setup Analyzer gives false positive when complex argument constraint used in indexer #1072

Closed
blairconrad opened this issue Apr 28, 2017 · 5 comments
Assignees
Milestone

Comments

@blairconrad
Copy link
Member

blairconrad commented Apr 28, 2017

Found in the Nancy codebase.
Can be reproduced by

namespace TheNamespace
{
    using FakeItEasy;

    public interface IHaveAnIndexer { string this[int context] { get; } }

    public class TheClass
    {
        public void Test()
        {
            var fake = A.Fake<IHaveAnIndexer>();
            A.CallTo(() => fake[A<int>._]).MustHaveHappened();
        }
    }
}
@blairconrad
Copy link
Member Author

Does not occur when A<int>._ is replaced by a literal, or when the indexer is replaced by a method.

@blairconrad
Copy link
Member Author

Seems to me that we're getting the false positive because we're looking for ancestors of A<int>._, looking for the first InvocationExpressionSyntax, which is A.CallTo(() => fake[A<int>._]), but there's an intervening ElementAccessExpressionSyntax node (fake[A<int>._]) that should have stopped us walking up the tree.
In VB.NET, the equivalent node is an InvocationExpressionSyntax (fake(A(Of Integer).Ignored).)

@thomaslevesque
Copy link
Member

Yes, so the issue should only happen for C#, not VB.
I can fix it when I get back, so the fix can be included in 3.3.0 (unless you want to do it of course)

@blairconrad
Copy link
Member Author

You are probably all vacationy so didn't notice that I self-assigned and marked in-progress. I am on top of this!
I enjoy an opportunity to demonstrate my complete lack of understanding of analyzer issues, submit a fix, and have you tell me it's wrong!
Srsly, though, I'll upload a commit in a few minutes.

@blairconrad
Copy link
Member Author

This issue was fixed in Release 3.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants