S3626 Does not detect redudent jump statement

Rule S3626: Jump statements should not be redundant tries to detect jump statements (continue) statements that are redundant.

If we look to the following example:

public class NonCompliant
{
    void Continue(IEnumerable<int> numbers)
    {
        foreach (var n in numbers)
        {
            if (n is not 42) continue; // FN
        }
    }
}

The continue statement is redundant, but not detected. If we change n is not 42 to n != 42, the rule works as expected. Apparently the is not pattern matching is not taken into consideration.

Reported by SonarAnalyzer.CSharp v10.17.0.131074

Anyone?

Hi,

This is flagged for the language experts. Hopefully they’ll be along soon (but TBH, they’ve got quite a backlog :frowning: )

 
Ann

Thanks for the report and the clear reproducer — this is indeed a false negative.

The rule uses control flow analysis to determine whether a continue statement is redundant. When the condition uses C# 9 pattern syntax (such as is not 42), our analyzer is unable to process the control flow for that method and silently skips it entirely — meaning no continue statements in the method are flagged, even if they are genuinely redundant.

The same limitation affects several other rules that rely on the same control flow analysis: S1854 (dead stores), S2190 (infinite recursion), S3257 (redundant member initializers), and S1172 (unused method parameters).

We have created an internal reproducer for this case and the fix has been added to our backlog.

1 Like

Success with the general improvements.