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

S1940: FP with null-conditional operator #2427

Closed
k0balt opened this issue May 20, 2019 · 1 comment · Fixed by #2446
Closed

S1940: FP with null-conditional operator #2427

k0balt opened this issue May 20, 2019 · 1 comment · Fixed by #2446
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@k0balt
Copy link

k0balt commented May 20, 2019

Repro steps

public static bool IsNullOrEmpty<T>(this IList<T> collection)
    => !(collection?.Count > 0);

Expected behavior

Rule S1940 should not triggered

Actual behavior

On example above sonar suggest replace !(collection?.Count > 0) with collection?.Count <= 0, but if collection == null conditions are not equal.
In same time, in this code:

public static bool IsNotPositive(this int? num)
    => !(num > 0);

Sonar doesn't suggest replacement (and that's right behavior).

Related information

  • SonarC# Version 4.9.0.4316
  • Visual Studio Version 15.9.12
@andrei-epure-sonarsource andrei-epure-sonarsource added this to the Support milestone May 21, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource added Area: C# C# rules related issues. Area: Rules Area: VB.NET VB.NET rules related issues. Type: False Positive Rule IS triggered when it shouldn't be. labels May 22, 2019
@andrei-epure-sonarsource
Copy link
Contributor

andrei-epure-sonarsource commented May 22, 2019

thanks @k0balt for the detailed reproducer. I confirm the behavior in 7.14

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: VB.NET VB.NET rules 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.

3 participants