S1854 fires when only reference to a local variable is in a returned tuple

The following code incorrectly causes S1854: remove this useless assignment to local variable ‘x’

        private int Bar() => 1;
        public (int,int) Foo()
        {
            var x = Bar();
            return (1, x);
        }

This is with scanner version 8.3.0.14607

Hi @paulhickman,

We can confirm that a false positive is raised in this case (https://github.com/SonarSource/sonar-dotnet/issues/3094).

This was handled in the current sprint and will be fixed in the next version (8.4).

Thank you,
Costin

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