From c816620579e363f7c0082e14754f9a51038465c6 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Wed, 19 Jun 2024 11:50:25 +0200 Subject: [PATCH] S4158: Add repro for #9444 --- .../EmptyCollectionsShouldNotBeEnumerated.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/EmptyCollectionsShouldNotBeEnumerated.cs b/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/EmptyCollectionsShouldNotBeEnumerated.cs index 09d2b2fe6b3..015130ac6aa 100644 --- a/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/EmptyCollectionsShouldNotBeEnumerated.cs +++ b/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/EmptyCollectionsShouldNotBeEnumerated.cs @@ -1218,3 +1218,26 @@ void Test(List aList) collectionOfIds.Clear(); // Noncompliant FP } } + +//https://github.com/SonarSource/sonar-dotnet/issues/9444 +class Repro9444 +{ + List Numbers { get; set; } + + void Initialize() + { + Numbers = new List(); + InitializeNumbers(); + foreach (var number in Numbers) // Noncompliant FP + { + System.Console.WriteLine(number); + } + } + + void InitializeNumbers() + { + Numbers.Add(1); + Numbers.Add(2); + Numbers.Add(3); + } +}