Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S2589 FP: Deconstructing a tuple in foreach loop #7489

Closed
dawust opened this issue Jun 21, 2023 · 2 comments · Fixed by #7750
Closed

Fix S2589 FP: Deconstructing a tuple in foreach loop #7489

dawust opened this issue Jun 21, 2023 · 2 comments · Fixed by #7750
Assignees
Labels
Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Milestone

Comments

@dawust
Copy link

dawust commented Jun 21, 2023

Description

When deconstructing a tuple in a foreach declaration S2589 is triggered on an unrelated variable.

Repro steps

public static class Program
{
    public static void Main()
    {
        long? value;
        var hasValue = true;
        while (hasValue)
        {
            value = null;
            hasValue = value.HasValue;

            foreach (var (a,b) in new List<(int, int)>())
            {
                // triggers S2589 on hasValue
            }
            
            foreach (var x in new List<(int, int)>())
            {
                var (a, b) = x;
                // does not trigger S2589 on hasValue
            }
        }
    }
}

Expected behavior

S2589 is not triggered

Actual behavior

S2589 is triggered

Related information

  • C#/VB.NET Plugins version: SonarAnalyzer.CSharp 9.4.0.72892
  • Rider 2022.3.3
  • MSBuild / dotnet version: 7.0.203
  • Operating System: Windows 11
@pavel-mikula-sonarsource
Copy link
Contributor

Hi @dawust,

Thank you for reporting this case, I confirm it as False Positive.

We plan to reimplement the rule in Q3 and that should fix this problem.

@mary-georgiou-sonarsource
Copy link
Contributor

Fixed by #7750

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants