Sonar-dotnet: Fix S1172 FP: Tuple as private method argument is marked as unused

Created on 18 Feb 2020  路  5Comments  路  Source: SonarSource/sonar-dotnet

Description

When using a tuple as a parameter in a method, S1172 pops even if the tuple is used in the method.

Repro steps

Code example:

        void UpdateControlsOnSignalChanged((InputsOutputs adress, bool state)? e) // <= False positive here
        {
            var call = new IPCQuery(nameof(DiagnosticsAPI.SignalChanged))
            { Data = (e?.adress, e?.state) };
            _pollingPublisher.Send(call);
        }

Expected behavior

if the tuple passed as a parameter is used in the method, S1172 shouldn't pop.

Actual behavior

S1172 pops no matter what is the usage of the tuple passed as a parameter.

Known workarounds

Suppress the warning locally.

Related information

  • SonarLint 4.17.0.14702
  • Visual Studio 2019 v 16.4.5
  • .Net Core 3.1 - LangVersion 8 - Nullable activated
  • Windows 10 Pro 1909
C# CFG False Positive

All 5 comments

Hi @Thieum ,

thank you for reporting this. We're able to reproduce the issue. Minimum reproducible scenario looks like this:

object TupleArgument((string adress, bool state)? e) // Noncompliant FP
{
    return new { Data = (e?.adress, e?.state) };
}

Interesting thing is that FP is not raised with public method.

public object PublicTupleArgument((string adress, bool state)? e) // Compliant for public method
{
    return new { Data = (e?.adress, e?.state) };
}

Hey,

I see this is marked as merged, but I still see the issue?

// a & b are marked with S1172           
            public void Test(string a, string b)
            {
                Test2((a, b));
            }

            public void Test2((string, string) a)
            {
                Test(a.Item1, a.Item2);
            }

@yfital I might be wrong but I think it's juste the repro (failing test) that has been merged, not the fix.

@Thieum you're right.

@yfital the title of the merged PR was Add repro for S1172 FP. So we have documented FP in our code base but the issue is not fixed yet.

This will be fixed in #3255

Was this page helpful?
0 / 5 - 0 ratings