S1854 False Positive: S1854 (Unused assignments should be removed)

When using “Local functions” C# feature some variables may be captured by local function and this may cause false positive for S1854.

The following code produces it in line 3.

public int Test()
    int i = 5;
    return Square();
    // Local function
    int Square() => i * i;

Hi @Alex_Broitman,

This is a known issue. You can follow the progress here: S1854 false positive when a variable is used inside local function · Issue #3126 · SonarSource/sonar-dotnet · GitHub


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.