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

S2589 FP: Rule is erroneously raised on var-type pattern matches that use when clauses #8011

Closed
rjgotten opened this issue Sep 14, 2023 · 1 comment · Fixed by #8421
Closed
Assignees
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Sprint: SE Short-lived* label for epic MMF-3077 *troll Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
Milestone

Comments

@rjgotten
Copy link

rjgotten commented Sep 14, 2023

Description

S2589 is erroneously raised on var-type pattern matches in e.g. switch expressions that implement the condition using a when clause.

Repro steps

[Flags]
public enum Flags
{
  None,
  Foo,
  Bar
}

// ...

public int Test(Flags flags)
{
  return flags switch
  {
    var value when value.HasFlag(Flags.Foo) => 1,
    var value when value.HasFlag(Flags.Bar) => 2,
    _ => 0
  };
}

Expected behavior

Rule S2589 is not raised.

Actual behavior

Rule S2589 is raised on both var value when pattern matches.

Known workarounds

Disable or suppress S2589.

Related information

  • C#/VB.NET Plugins version: 9.8 (via SonarLint v7.3.0.77872)
  • Visual Studio version: VS2022 v17.7.4
  • MSBuild / dotnet version: .NET SDK 7.0.401
  • SonarScanner for .NET version (if used): N/A
  • Operating System: Windows 11
@gregory-paidis-sonarsource
Copy link
Contributor

Hey @rjgotten ,

Thanks for the information.
I added a reproducer you can find here: #8014

I also added to our dedicated backlog, where it will be taken care of sometimes in the future.

@gregory-paidis-sonarsource gregory-paidis-sonarsource added Area: CFG/SE CFG and SE related issues. Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. and removed Area: C# C# rules related issues. labels Sep 14, 2023
@gregory-paidis-sonarsource gregory-paidis-sonarsource changed the title Fix S2589 FP: Rule is erroneously raised on var-type pattern matches that use when clauses S2589 FP: Rule is erroneously raised on var-type pattern matches that use when clauses Sep 14, 2023
@gregory-paidis-sonarsource gregory-paidis-sonarsource removed their assignment Sep 14, 2023
@github-actions github-actions bot added this to Review in progress in Best Kanban Nov 29, 2023
@Tim-Pohlmann Tim-Pohlmann added Area: C# C# rules related issues. Sprint: SE Short-lived* label for epic MMF-3077 *troll labels Nov 30, 2023
@github-actions github-actions bot moved this from Review in progress to In progress in Best Kanban Dec 1, 2023
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Dec 5, 2023
@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Dec 6, 2023
@Tim-Pohlmann Tim-Pohlmann modified the milestones: 9.15, 9.16 Dec 6, 2023
@pavel-mikula-sonarsource pavel-mikula-sonarsource removed their assignment Dec 14, 2023
Best Kanban automation moved this from Review approved to Validate Peach Dec 14, 2023
@Tim-Pohlmann Tim-Pohlmann moved this from Validate Peach to Done in Best Kanban Dec 19, 2023
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. Area: CFG/SE CFG and SE related issues. Sprint: SE Short-lived* label for epic MMF-3077 *troll Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

5 participants