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

@github-actions github-actions bot added this to In progress in Best Kanban Aug 23, 2023
@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 Short-lived* label for epic MMF-3077 *troll 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
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban 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.

@github-actions github-actions bot moved this from Review in progress to In progress in Best Kanban Aug 24, 2023
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
@github-actions github-actions bot moved this from In progress to Review in progress in Best Kanban Aug 24, 2023
@@ -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

@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Aug 25, 2023
@sonarcloud
Copy link

sonarcloud bot commented Aug 28, 2023

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

@sonarcloud
Copy link

sonarcloud bot commented Aug 28, 2023

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
22 checks passed
Best Kanban automation moved this from Review approved to Validate Peach Aug 28, 2023
@Tim-Pohlmann Tim-Pohlmann deleted the Tim/S4158_Clear branch August 28, 2023 13:45
@mary-georgiou-sonarsource mary-georgiou-sonarsource moved this from Validate Peach to Done in Best Kanban Sep 1, 2023
@Tim-Pohlmann Tim-Pohlmann moved this from Done to Validate Peach in Best Kanban Sep 1, 2023
@Tim-Pohlmann Tim-Pohlmann moved this from Validate Peach to Done in Best Kanban Sep 1, 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. Area: VB.NET VB.NET rules related issues. Sprint: SE Short-lived* label for epic MMF-3077 *troll Type: False Negative Rule is NOT triggered when it should be.
Projects
Best Kanban
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants