From 2ecd820641990ce149fa547bee3907ea1e09ed78 Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Wed, 27 Sep 2023 14:15:00 +0200 Subject: [PATCH 1/2] add repro --- .../ConditionEvaluatesToConstant.CSharp8.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp8.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp8.cs index 0c779520c17..285de492041 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp8.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp8.cs @@ -495,3 +495,21 @@ int SwitchExpression() }; } } + +// https://github.com/SonarSource/sonar-dotnet/issues/8094 +class Repro8094 +{ + public void TestMethod() + { + Action? someDelegate = delegate { }; + someDelegate += Callback; + + someDelegate -= Callback; + + if (someDelegate == null) // Noncompliant {{Change this condition so that it does not always evaluate to 'False'.}} + { } + + } + + private void Callback() { } +} From 4510946fc104306c9836d9696653dee36312e444 Mon Sep 17 00:00:00 2001 From: Mary Georgiou <89914005+mary-georgiou-sonarsource@users.noreply.github.com> Date: Wed, 27 Sep 2023 16:32:26 +0200 Subject: [PATCH 2/2] Update ConditionEvaluatesToConstant.CSharp8.cs --- .../Roslyn/ConditionEvaluatesToConstant.CSharp8.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp8.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp8.cs index 285de492041..79f9fd3a80b 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp8.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestCases/SymbolicExecution/Roslyn/ConditionEvaluatesToConstant.CSharp8.cs @@ -503,12 +503,9 @@ public void TestMethod() { Action? someDelegate = delegate { }; someDelegate += Callback; - someDelegate -= Callback; - if (someDelegate == null) // Noncompliant {{Change this condition so that it does not always evaluate to 'False'.}} { } - } private void Callback() { }