diff --git a/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp12.cs b/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp12.cs index da77db99faa..de9b44d0f2b 100644 --- a/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp12.cs +++ b/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp12.cs @@ -1,4 +1,6 @@ using System; +using System.Linq; +using System.Collections.Generic; class Sample { @@ -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 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 + } + } }