SonarSource/sonar-dotnet

Fix S1854 FP: Raises when variable is assigned in expression that is part of ternary condition

Closed this issue · 1 comments

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);
    }
}

This is the same root cause as #9472.