-
Notifications
You must be signed in to change notification settings - Fork 227
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 S3900 and S2259 FN: Support method dereference #7011
Fix S3900 and S2259 FN: Support method dereference #7011
Conversation
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
One question about the test cases.
|
||
public void WithDelegate(object asParameter, object asVariable) | ||
{ | ||
if(asParameter == 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.
[Educational] How is checking for null sets the null state for these variables? Shouldn't S2259 only raise an issue if it's certain that the variable null when it's being dereferenced? Shouldn't it be like this:
if(asParameter == null)
{
SomeAction(asParameter.ToString); // Noncompliant
}
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.
if(asParameter=null) {
// Here, we're certain that asParametr has Null
} else {
// Here, we're certain that asParamet has NotNull. Even when it's empty.
}
// Here, we will arrive twice: Once asParametr=Null, once asParametr=NotNull
More user-likely scenario is
if(arg !=null) {
DoSomething(arg.ToString)
} else {
// And here, we're sure arg==Null. Even if the `else` is not present, such state is possible
}
arg.ToString(); // Noncompliant, this should have been in the "if" branch. We arrive twice here.
d1fa962
to
d6211d9
Compare
1023f38
to
7d50545
Compare
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! |
Part of #6997
There will be a rebase conflict with #7004 refactoring.