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 S4158 FN: Learn Empty on Clear #7861

Merged
merged 4 commits into from
Aug 28, 2023
Merged

Fix S4158 FN: Learn Empty on Clear #7861

merged 4 commits into from
Aug 28, 2023

Conversation

Tim-Pohlmann
Copy link
Contributor

@Tim-Pohlmann Tim-Pohlmann commented Aug 23, 2023

Part of #7457

We do not learn CollectionEmpty from list.Clear().

var list = new List<int> { 1 };
list.Clear();   // Compliant
list.Clear();   // FN

@Tim-Pohlmann Tim-Pohlmann changed the title Tim/s4158 clear Fix S4158 FN: Learn Empty on Clear Aug 23, 2023
@Tim-Pohlmann Tim-Pohlmann changed the base branch from master to Tim/S4158_Remove August 23, 2023 09:23
@Tim-Pohlmann Tim-Pohlmann added Type: False Negative Rule is NOT triggered when it should be. Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. Sprint: SE labels Aug 23, 2023
@Tim-Pohlmann Tim-Pohlmann added this to the 9.9 milestone Aug 23, 2023
@Tim-Pohlmann Tim-Pohlmann added Type: False Negative Rule is NOT triggered when it should be. Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. and removed Type: False Negative Rule is NOT triggered when it should be. Area: CFG/SE CFG and SE related issues. Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. labels Aug 23, 2023
Copy link
Contributor

@mary-georgiou-sonarsource mary-georgiou-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicks and questions

@@ -531,6 +539,8 @@ public void LearnConditions_Size(bool condition, List<int> arg)
var empty = new List<int>();
var notEmpty = new List<int>() { 1, 2, 3 };

// the tests below are messy for as long as we unlearn CollectionConstraints on empty.Count()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty.Count() will (wrongly) unlearn CollectionConstraint due to it being an extension method. The UTs here do not take this into consideration and thus provide unexpected results. They should be fixed when Count() does not unlearn anymore.

Base automatically changed from Tim/S4158_Remove to master August 24, 2023 14:26
@Tim-Pohlmann Tim-Pohlmann marked this pull request as ready for review August 24, 2023 15:19
@@ -195,7 +195,8 @@ private ProgramState ProcessInvocation(SymbolicContext context, IInvocationOpera
}
}
return ProcessAddMethod(context.State, invocation.TargetMethod, instance)
?? ProcessRemoveMethod(context.State, invocation.TargetMethod, instance);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:
Maybe you can retrieve once the invocation.TargetMethod.Name and pass it to all the calls as an argument.

Copy link
Contributor

@mary-georgiou-sonarsource mary-georgiou-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one nitpick

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@Tim-Pohlmann Tim-Pohlmann merged commit 71b48cf into master Aug 28, 2023
@Tim-Pohlmann Tim-Pohlmann deleted the Tim/S4158_Clear branch August 28, 2023 13:45
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. Area: VB.NET VB.NET rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants