From 406059a48d3359055d4ea96a8b6ae41a2a849000 Mon Sep 17 00:00:00 2001 From: Gregory Paidis <115458417+gregory-paidis-sonarsource@users.noreply.github.com> Date: Thu, 21 Mar 2024 08:51:42 +0100 Subject: [PATCH] S3966 FP Repro (#8964) --- .../ObjectsShouldNotBeDisposedMoreThanOnce.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ObjectsShouldNotBeDisposedMoreThanOnce.cs b/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ObjectsShouldNotBeDisposedMoreThanOnce.cs index adebcfb720f..95956d456e3 100644 --- a/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ObjectsShouldNotBeDisposedMoreThanOnce.cs +++ b/analyzers/tests/SonarAnalyzer.Test/TestCases/SymbolicExecution/Roslyn/ObjectsShouldNotBeDisposedMoreThanOnce.cs @@ -282,3 +282,16 @@ void CloseTwiceDBConnection(DbConnection connection) connection.Close(); // Compliant - close() in DB connection does not dispose the connection object. } } + +// https://github.com/SonarSource/sonar-dotnet/issues/8946 +public class Repro_8946 +{ + static void Method(T[] array) + { + for (int i = 0; i < array.Length; i++) + if (array[i] is IDisposable d) + { + d.Dispose(); // Noncompliant FP + } + } +}