Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S1854 FN: Support &&, ||, ?? and ??= #4937

Open
pavel-mikula-sonarsource opened this issue Sep 30, 2021 · 2 comments · Fixed by #9536 or #9591
Open

Fix S1854 FN: Support &&, ||, ?? and ??= #4937

pavel-mikula-sonarsource opened this issue Sep 30, 2021 · 2 comments · Fixed by #9536 or #9591
Assignees
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Type: False Negative Rule is NOT triggered when it should be.

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

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
        }
@pavel-mikula-sonarsource pavel-mikula-sonarsource added Area: C# C# rules related issues. Area: C#8 Area: CFG/SE CFG and SE related issues. Type: False Negative Rule is NOT triggered when it should be. labels Sep 30, 2021
@pavel-mikula-sonarsource pavel-mikula-sonarsource added this to the 8.30 milestone Sep 30, 2021
@pavel-mikula-sonarsource
Copy link
Contributor Author

This should also solve this FN:

            DeadStores lst;
            lst = new DeadStores  // FN
            {
                Property = 42
            };
            lst = new DeadStores
            {
                Property = 42
            };
            lst.ToString();

@Tim-Pohlmann
Copy link
Contributor

The validation has revealed a problem. I re-open this ticket. We either need to fix or revert the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Type: False Negative Rule is NOT triggered when it should be.
Projects
None yet
3 participants