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 S1940: "Inverted boolean checks" should not suggest inversion for Nullable<T> #297

Closed
sm-g opened this issue May 11, 2017 · 1 comment
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@sm-g
Copy link

sm-g commented May 11, 2017

RSPEC-1940

Repro steps

void Foo(string pid, int? id) {
  if (pid == null && !(id > 0))
  {
     // should be either pid or id
  }
}

Expected behavior

No trigger of S1940 rule.

Actual behavior

SL suggests to replace it with:

 if (pid == null && (id <= 0))

but id <= 0 is false when id==null

Related information

  • SonarC# 1.23.0.1857
  • Visual Studio 15.1
@Evangelink Evangelink added Area: Rules Type: False Positive Rule IS triggered when it shouldn't be. labels May 11, 2017
@Evangelink
Copy link
Contributor

Hi @sm-g !

Thanks for the feedback. Indeed there is a bug on our side which is related to nullable value (another linked ticket is #152).

@valhristov valhristov changed the title S1940 for nullable numeric invalid Fix S1940: should not suggest check inversion for Nullable<T> May 11, 2017
@valhristov valhristov added this to the next-version milestone May 11, 2017
@valhristov valhristov self-assigned this May 31, 2017
@valhristov valhristov changed the title Fix S1940: should not suggest check inversion for Nullable<T> Fix S1940: "Inverted boolean checks" should not suggest inversion for Nullable<T> Jun 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

3 participants