SonarSource / sonar-dotnet

Code analyzer for C# and VB.NET projects
https://redirect.sonarsource.com/plugins/csharp.html
GNU Lesser General Public License v3.0
755 stars 223 forks source link

Fix S1854 FP: Value used in `catch` or `when` should LiveIn for all try blocks #9447

Closed pavel-mikula-sonarsource closed 2 weeks ago

pavel-mikula-sonarsource commented 2 weeks ago

Should not raise in complex scenarios related to Roslyn LVA:

public void UsedInFinally()
{
            int value = 42; // Noncompliant FP
            try
            {
                SomethingThatCanThrow();
                value = 0;
            }
            catch
            {
                Use(value);
            }
}