S2933 False Positive

Please provide

  • Operating system: Windows 10
  • Visual Studio version: VS 2022 version 17.10.3
  • SonarLint plugin version: 7.3.077872
  • Programming language you’re coding in: C#
  • Is connected mode used: no

And a thorough description of the problem / question:

The following line of code triggered the warning S2933 (“Make xxx readonly”).
private bool isFrontRendering = true;
But, in one of the functions of this class, i call the following function:
isFrontRendering.Toggle();
Defined by:

public static void Toggle(this ref bool value) {
    value = !value;
}

As the value changes by reference inside the extension functions, the rule S2933 should not appear.

Hey there.

First things first – can you check that the FP persists on the latest version of the extension, v8.6?

Oh, I thought VS had auto updates for extensions. Just updated to sonar lint version 8.6.0.10679 and the issue still persists here.

Hi @Agentew04! I confirm this as a FP, at this moment we do not support extension methods. Thanks a lot for reporting it, I added a reproducer on our side to keep track of it.

public class MyClass
{
    private bool myField = true; // FP

    public void ToggleField()
    {
        myField.Toggle();
    }
}

public static class BoolExtension
{
    public static void Toggle(this ref bool value)
    {
        value = !value;
    }
}