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 assigned in expression that is part of ternary condition #9471

Closed mary-georgiou-sonarsource closed 2 months ago

mary-georgiou-sonarsource commented 3 months ago

Repro steps

void Repro(bool condition)
{
    byte[]? tempArray = null;
    _ = condition
        ? tempArray = new byte[42]  // Noncompliant FP
        : new byte[24];
    if (tempArray != null)
    {
        Console.WriteLine(tempArray);
    }
}
sebastien-marichal commented 2 months ago

This is the same root cause as #9472.