Skip to content

Commit

Permalink
NET-371 S2583: Add reproducer for #9671
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianAmbrosini authored and sonartech committed Oct 3, 2024
1 parent 101c02f commit 9e13a1b
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Linq;
using System.Collections.Generic;

class Sample
{
Expand Down Expand Up @@ -49,4 +51,27 @@ void CollectionExpressions(int[] array)
if (unknownLength2.Length == 0) { } // Compliant
if (unknownLength2.Length < 0) { } // Noncompliant
}

// Repro for https://github.com/SonarSource/sonar-dotnet/issues/9671
void ListFilledInLocalFunction()
{
List<int> list = new();
foreach (var item in Enumerable.Range(0, 5))
{
if (item % 2 == 0)
{
LocalFunction(item);
}

void LocalFunction(int added)
{
list.Add(added);
}
}

if (list.Count > 0) // Noncompliant FP
{
Console.WriteLine("This code is reachable"); // Secondary FP
}
}
}

0 comments on commit 9e13a1b

Please sign in to comment.