-
Notifications
You must be signed in to change notification settings - Fork 232
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
SE: Move CollectionConstraint from S4158 to the engine (part 1) #8702
SE: Move CollectionConstraint from S4158 to the engine (part 1) #8702
Conversation
...zers/src/SonarAnalyzer.Common/SymbolicExecution/Roslyn/OperationProcessors/ObjectCreation.cs
Outdated
Show resolved
Hide resolved
&& CollectionCreationConstraint(context.State, operation) is { } constraint) | ||
{ | ||
return context.SetOperationConstraint(constraint) | ||
.SetOperationConstraint(operation, ObjectConstraint.NotNull); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is setting the NotNull
constraint as well useful?
It didn't happen before, but I do not think it can be null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be logic somewhere that handles this case already. Make sure it still works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the UTs, it seems to be working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because you are setting it here. What I'm saying is there should be code somewhere that is setting NotNull
already. Remove your code and see if it still works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misunderstood what you meant.
You are both correct and wrong:
- It does not work if I remove it
- There is indeed code somewhere that is setting it to
NotNull
. And it's 20 lines down :)
I basically over-wrote the previous behavior by adding this if-arm.
I re-structured the conditionals a bit, I think it makes more sense no
96aa5ee
to
9278c4a
Compare
9278c4a
to
52eb017
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract everything into a new class and we should be good.
...zers/src/SonarAnalyzer.Common/SymbolicExecution/Roslyn/OperationProcessors/ObjectCreation.cs
Outdated
Show resolved
Hide resolved
...zers/src/SonarAnalyzer.Common/SymbolicExecution/Roslyn/OperationProcessors/ObjectCreation.cs
Outdated
Show resolved
Hide resolved
KnownType.System_Collections_Immutable_IImmutableArray_T, | ||
KnownType.System_Collections_Generic_Dictionary_TKey_TValue, | ||
KnownType.System_Collections_Generic_IDictionary_TKey_TValue, | ||
KnownType.System_Collections_Immutable_IImmutableDictionary_TKey_TValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, this will be private and consumers will just query this class via static methods.
I want to do this gradually, so I will leave it public for now and pluck the references one by one in smaller PRs.
da8d5ba
to
879d2d8
Compare
879d2d8
to
64dfe46
Compare
var declared = new Exception(); | ||
assigned = new EventArgs(); | ||
var collection1 = new List<int>(); | ||
collection1.Add(42); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails to set the constraint from empty to non-empty, because it's part of the rule (for now)
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done! Only some naming suggestions.
Part of #7866
Moves the following logic from the rule to the
ObjectCreation
processor: