From 0055b88bea091b86c0c9c02d23ed82258b1cc3e4 Mon Sep 17 00:00:00 2001 From: Mary Georgiou <89914005+mary-georgiou-sonarsource@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:08:36 +0100 Subject: [PATCH] S2589: Add FP repro for #8449 (#8453) --- .../Roslyn/ConditionEvaluatesToConstant.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.cs index 51d1f1ded1b..916e8166433 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.cs @@ -3458,6 +3458,7 @@ private void Test() Console.WriteLine(); } } + public class Repro_8445_OtherClass { public static readonly int readonlyStaticInt = 42; @@ -3465,3 +3466,20 @@ public class Repro_8445_OtherClass public readonly int readonlyInt = 42; public readonly string readonlyString = "42"; } + +// Reproducer for https://github.com/SonarSource/sonar-dotnet/issues/8449 +public class Repro_8449 +{ + public static void Foo() + { + int delay = 100; + while (true) + { + if (delay < 1000) // Noncompliant {{Change this condition so that it does not always evaluate to 'True'.}} FP + // ^^^^^^^^^^^^ + { + delay = delay * 2; + } + } + } +}