-
Notifications
You must be signed in to change notification settings - Fork 229
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 S2259 FP: SE engine doesn't take into account element existence collection methods #9505
Conversation
f19c0eb
to
a308ece
Compare
4d270cc
to
11777a0
Compare
11777a0
to
ba04919
Compare
symbol.IsExtensionMethod switch | ||
{ | ||
true => symbol.Parameters.Length > 1, | ||
false => !symbol.Parameters.IsEmpty | ||
}; |
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.
symbol.IsExtensionMethod switch | |
{ | |
true => symbol.Parameters.Length > 1, | |
false => !symbol.Parameters.IsEmpty | |
}; | |
symbol.IsExtensionMethod | |
? symbol.Parameters.Length > 1 | |
: !symbol.Parameters.IsEmpty; |
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.
LGTM (review was mostly done sync with @mary-georgiou-sonarsource and @Tim-Pohlmann)
61234cf
to
11c153d
Compare
Quality Gate passed for 'Sonar .NET Java Plugin'Issues Measures |
Quality Gate passed for 'SonarAnalyzer for .NET'Issues Measures |
Tag("Value", value); | ||
"""; | ||
var validator = SETestContext.CreateCS(code, $"List<object> collection").Validator; | ||
validator.TagValue("Value").Should().HaveOnlyConstraint(ObjectConstraint.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.
You can merge these tests into one if you extract the collection type into a parameter:
"List<object>"
"Dictionary<int, object>"
- etc.
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 but I'm testing different things - in one case it's a reference that can return null and in the other case it never returns cause the keyvalue pair is a struct.
Fixes #8266