Quickfix for C# rule S927 does not work properly for overloaded functions

  • Operating system: Windows 10
  • Visual Studio version: 17.12.3
  • SonarQube for Visual Studio plugin version: 8.11.0.11944
  • Programming language you’re coding in: C#
  • Is connected mode used: No

The quickfix for the rule S927 incorrectly changes the name of parameters if the corresponding method has overloads defined in the interface. (I applied the quickfix to the whole project at once)

Example:

public interface IFace
{
  void Foo(string fooString);
  void Foo(System.Text.RegularExpressions.Regex fooRegex);
}

and the implementation

public class MyImpl : IFace
{
  public void Foo(string barString) // NONCOMPLIANT with S927
  {
    // [...]
  }

  public void Foo(System.Text.RegularExpressions.Regex barRegex) // NONCOMPLIANT with S927
  {
    // [...]
  }
}

Then after applying the quickfix, it will look like this:

public class MyImpl : IFace
{
  public void Foo(string fooString) // COMPLIANT
  {
    // [...]
  }

  public void Foo(System.Text.RegularExpressions.Regex fooString) // Still NONCOMPLIANT with S927
  {
    // [...]
  }
}

The quickfix will change the name to fooString for both overloads of the function instead of using fooRegex for the second overload.

I can reproduce this. However, the code fix I’ve got is from Microsoft: CA1725. So I think you should report the code fix issue elsewhere. Note that someone else already did: CA1725 rule matches method against wrong method on interface.

Ah, my bad. I didn’t check thoroughly and assumed because the issue was raised by Sonar, the corresponding quickfix also came from Sonar.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.