Issue: Rule S2583: False positive when using ? with a bool? and false

Here is the method that exhibits the issue:

        private static void AddIfSet(StringBuilder sb, string propName, bool? propValue)
            if (propValue ?? false)
                sb.Append($"{propName}, ");

SonarLint issues the warning "S2583 Change this condition so that it does not always evaluate to ‘false’."
To me this is just incorrect - the branch is taken only if propValue is true, so it doesn’t always evaluate to false.

Hi @DinkHome

Since the method is private, SonarLint will look at the flow of the code calling this method, trying to determine all possible paths. This is hard to tell without the entire code, but are you sure there is a path that will call this method with propValue not equal to false?

AFAIK there is currently no way in SonarLint for VS to visualize the issue flows, so one thing you can try is to analyze your code on SonarQube community edition, and see if the same issue is reported. In SonarQube, clicking on the issue, you should be able to see the flow, that will help to understand the issue.