[BUG] "S1116: Remove this empty statement" false positive when using C# 12 collection expressions

I’m using C# 12 collection expressions to pass in a collection of items to a constructor:

// Pass an empty collection as an argument
var cache = new CustomFormatCache([]);

The primary constructor signature is:

public class CustomFormatCache(IEnumerable<TrashIdMapping> mappings) {...}

The analysis warning I get puts a yellow-squiggly under the semicolon, as shown in the screenshot below:

image

My expectation is that this warning is not presented, because this is clearly not an empty statement. I suspect the SonarLint plugin doesn’t know how to parse collection expressions.

  • Plugin version: 10.0.1.77000
  • Rider version: 2023.3 RC 1

Hi @voidpointer!
We support .Net 8 and C# 12 syntax starting from version 9.3 of the analyzer.
SonarLint for IntelliJ recently embedded this version on release 10.1.0.77128.

Can you please try again with the latest plugin version?

Thanks for the reply. I’m using version 10.1.1.77150 and I still see the issue.

Hi, sorry for the delay.
So I started looking into this and it appears not to be on our side.
The rule implementation is trivial and it’s raising for every EmptyStatementSyntax.
Looking at the syntax with the current Roslyn main branch on Sharplab there is no EmptyStatement that could trigger our rule. Instead, with a less recent version suddenly an EmptyStatement appears after the LocalDeclarationStatement. This might explain why the rule was raising in your instance.

Are you using the latest version of the .Net 8 SDK from November 14?

Hi @voidpointer,
A user reported a similar issue, and it appears to be fixed by updating to SonarLint version 10.2.0.77238. Can you confirm?