SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
781 stars 226 forks source link

Fix S1854 FP: Raises when variable is reassigned in a using body after it has been already assigned in using statement. #9473

Closed mary-georgiou-sonarsource closed 2 months ago

mary-georgiou-sonarsource commented 3 months ago

S1854 FP

void Repro(IDisposable data)
{
    using (data = Something()) // Noncompliant
    {
        data = Something();   // Noncompliant FP
    }

    if (data != null)
    {
        Console.WriteLine("Hello");
    }
    IDisposable Something() => null;
}