Vannevelj / VSDiagnostics

A collection of static analyzers based on Roslyn that integrate with VS
GNU General Public License v2.0
65 stars 16 forks source link

Implement Equals and GetHashCode Code Fix Bug #614

Closed Hosch250 closed 6 years ago

Hosch250 commented 7 years ago

I encountered this failure with the following class:

namespace CheckersUI
{
    public sealed partial class App
    {
        public App()
        {
            InitializeComponent();
        }
    }
}
Vannevelj commented 7 years ago

What's the bug?

Hosch250 commented 7 years ago

I haven't checked yet. The code fix just has an error.

Hosch250 commented 7 years ago

It seems that it is picking something up in the .g.i.cs file for UWP and WPF projects. We'll have to ignore these locations in the code fixes as well as when firing analyzers (not when inspecting the code in analyzers, though). Reference #576

Hosch250 commented 7 years ago

After further research into this, I think I found the problem's root. We only have the root for one document:

var root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

This messes up the call when we try to get the type declaration node:

var node = (TypeDeclarationSyntax) root.FindNode(location.SourceSpan);

So, we just pick up a random node at that location in the document we are in. This means that rather than checking the node for members, we'll have to check the symbol for members we are interested in. Hmm, why didn't we do that in the first place?