csharpsquid:S3878 false positive for collection expression using spread operator


Hi, I observed this false positive for S3878 using the new C#12 collection expression feature (including a spread operator use) to pass arguments to a function taking params parameters.

I built a minimal reproduction which can be found on GitHub. It uses SonarAnalyzer.CSharp in version (currently most recent) and the latest version of SonarLint also reports it.

Here’s the gist of it in two screenshots:


Why is this a false positive

It’s not legal to simply pass the elements, because a is an int but bs is an int[], so we have to use the collection expression with the spread operator or the pre-C#12 equivalent linq expression (which does not report S3878).

Hello @ehonda and happy new year.

I confirm this is a false positive. I added an issue to our backlog to tackle in one of our next analyzer hardenings. You can follow it here.

Best regards,