sonar-dotnet
sonar-dotnet copied to clipboard
Fix S1854 FN: Support &&, ||, ?? and ??=
The LVA based on Roslyn CFG doesn't support Flow Capturing Operations. We need to support them to properly detect issues in cases where expression is translated into several CFG blocks.
private void ConditionalEvaluation(bool b1, bool b2, object coalesce, object coalesceAssignment)
{
var x = false; // Compliant ignored value
x = true; // Roslyn CFG FN: Consequence of inaccurate LVA state below
x = b1 && b2; // Roslyn CFG FN: Branching with FlowCaptureOperation
x = b1 || b2; // Roslyn CFG FN: Branching with FlowCaptureOperation
coalesce = coalesce ?? "Value"; // Roslyn CFG FN: Branching with FlowCaptureOperation
coalesceAssignment ??= "Value"; // Roslyn CFG FN: Branching with FlowCaptureOperation
}
This should also solve this FN:
DeadStores lst;
lst = new DeadStores // FN
{
Property = 42
};
lst = new DeadStores
{
Property = 42
};
lst.ToString();
The validation has revealed a problem. I re-open this ticket. We either need to fix or revert the PR.