Search code examples
c#sonarqubesonarlint

Rule S1144 "Remove unused private method" c# - VS 2015


Methods Visit(Leaf v) and Visit(Composite v) are marked as unused by SonarLint. Also SonarQube marks it as unused. But it invoked with dynamic. Does anybody knows how to fix it? Probably there some configuration? Entry point is one Visit(Base root), then using dynamic call it will traverse tree.

UPD: Updated example

This is sample:

public void Visit(Base root)
{
   Visit((dynamic)root);
}

private void Visit(Composite v )
{
    v.Children.ForEach(el => Visit((dynamic)el));
}

private void Visit(Leaf v)
{
    // do smth
}

class Base
{
} 

class Composite : Base
{
    public IEnumerable<Base> Children { get;}
}

class Leaf : Base
{

}

Solution

  • This is a false positive in SonarLint. Currently there's no fix for this. We should probably use the CandidateSymbols when we resolve the method reference. I created a ticket for it here: https://jira.sonarsource.com/browse/SLVS-1080