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 S4158 FN: Collection Expressions (C# 12) #8539

Open
zsolt-kolbay-sonarsource opened this issue Jan 15, 2024 · 0 comments
Open

Fix S4158 FN: Collection Expressions (C# 12) #8539

zsolt-kolbay-sonarsource opened this issue Jan 15, 2024 · 0 comments
Labels
Area: C# C# rules related issues. Area: C#12 C#12 related issues Area: CFG/SE CFG and SE related issues. Type: False Negative Rule is NOT triggered when it should be.

Comments

@zsolt-kolbay-sonarsource
Copy link
Contributor

zsolt-kolbay-sonarsource commented Jan 15, 2024

Description

Collection expressions are not handled by the SE engine, leading to FNs like this:

Repro steps

List<int> emptyList = [];
emptyList.Clear();                  // FN

ReadOnlySpan<int> emptySpan = [.. emptyList];
foreach (int element in emptySpan)  // FN
{
    Console.WriteLine(element);
}

Expected behavior

S4158 raises a warning.

Actual behavior

No S4158 warnings are raised.

Related information

  • C#/VB.NET Plugins version: 9.17
  • Visual Studio version: Visual Studio 2022 (17.8.4)
  • .NET version: 8.0
  • Operating System: Windows 10

Implementation

With version 4.9.2 of Microsoft.CodeAnalysis.CSharp collection expressions are supported on the CFG level (previously it was always a NoneOperation).
A new Processor class is needed in the SE engine that can handle ICollectionExpressionOperation types (and also for ISpreadOperation).

@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added Type: False Negative Rule is NOT triggered when it should be. Area: CFG/SE CFG and SE related issues. Area: C# C# rules related issues. Area: C#12 C#12 related issues labels Jan 15, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource changed the title Fix S4158 FN: C# 12 Collection Expressions Fix S4158 FN: Collection Expressions (C# 12) Jan 15, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added this to the 9.29 milestone Jul 2, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added the Sprint: Hardening Fix FPs/FNs/improvements label Jul 2, 2024
@sebastien-marichal sebastien-marichal removed this from the 9.29 milestone Jul 12, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource removed the Sprint: Hardening Fix FPs/FNs/improvements label Jul 16, 2024
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: C#12 C#12 related issues Area: CFG/SE CFG and SE related issues. Type: False Negative Rule is NOT triggered when it should be.
Projects
None yet
Development

No branches or pull requests

3 participants