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 S1172 FP: case when where the pattern is a constant #2010

Closed
tsleegers opened this issue Oct 16, 2018 · 4 comments · Fixed by #2493
Closed

Fix S1172 FP: case when where the pattern is a constant #2010

tsleegers opened this issue Oct 16, 2018 · 4 comments · Fixed by #2493
Labels
Area: C# C# rules related issues. Area: CFG/SE CFG and SE related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@tsleegers
Copy link

Description

When a function parameter only is used in het when clause of pattern matching in a switch statement it incorrecty marks that parameter as unused (S1172)

Repro steps

Please provide the steps required to reproduce the problem

Example code:

static int PatternMatch(StringSplitOptions splitOptions, int i)
{
    switch (splitOptions)
    {
        case StringSplitOptions.None
            when i > 0:
            return 1;
        default:
            return 0;
    }
}

Parameter i is marked unused.

Expected behavior

No warning from sonar analyzers.

Actual behavior

S1172 warning generated:
Warning S1172 Remove this parameter 'i', whose value is ignored in the method.

Known workarounds

Suppress warning.

Related information

  • SonarC# Version: 7.7.0.7192
  • Visual Studio Version: Visual Studio Professional 2017 (15.8.7 and 15.9.0 Preview 3)
@tsleegers tsleegers changed the title S1172 False positive when pattern matching with parameter (C# 7.7.0.7192) S1172 False positive when pattern matching with parameter Oct 16, 2018
@valhristov valhristov changed the title S1172 False positive when pattern matching with parameter Fix S1172: False positive when pattern matching with parameter Oct 17, 2018
@valhristov valhristov added Area: CFG/SE CFG and SE related issues. Area: LVA labels Oct 17, 2018
@valhristov valhristov added this to the CFG + Symbolic Execution milestone Oct 17, 2018
@valhristov
Copy link
Contributor

Thanks for reporting this problem @tsleegers, I managed to reproduce it, we will fix it in a future release.

Note to implementers: for this to be fixed the Live Variable Analysis needs to start analysing patterns.

@Herdo
Copy link

Herdo commented Jun 20, 2019

@valhristov Is there any progress on this issue?

@Herdo
Copy link

Herdo commented Jun 20, 2019

Or @andrei-epure-sonarsource ?

@andrei-epure-sonarsource andrei-epure-sonarsource modified the milestones: CFG + Symbolic Execution, 7.16 Jun 21, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource added Type: Improvement Type: False Positive Rule IS triggered when it shouldn't be. labels Jun 21, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource changed the title Fix S1172: False positive when pattern matching with parameter Fix S1172 FP: case when pattern matching with parameter Jun 21, 2019
@andrei-epure-sonarsource
Copy link
Contributor

andrei-epure-sonarsource commented Jun 21, 2019

@Herdo no progress yet. We plan to invest some effort this year to improve our Control Flow Graph.

@andrei-epure-sonarsource andrei-epure-sonarsource changed the title Fix S1172 FP: case when pattern matching with parameter Fix S1172 FP: case when where the pattern is a constant Jul 18, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource removed their assignment Jul 22, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource added the Area: C# C# rules related issues. label Aug 12, 2019
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. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants