-
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
S3655: Fields with methods, local functions, yield and async #6981
S3655: Fields with methods, local functions, yield and async #6981
Conversation
2d46646
to
d20bcf2
Compare
d20bcf2
to
50d2b5e
Compare
f7893e0
to
08ef95f
Compare
|
||
theField = null; | ||
_ = theField.Value; // Noncompliant, empty | ||
_ = theField.Value; // Compliant, when reached the ".Value" above implies aField is not 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.
_ = theField.Value; // Compliant, when reached the ".Value" above implies aField is not null | |
_ = theField.Value; // Compliant, when reached the ".Value" above implies theField is not null |
async Task WithAsyncAwait() | ||
{ | ||
_ = theField.Value; // Compliant, unknown | ||
await AnAsyncOperation(); | ||
|
||
theField = null; | ||
await AnAsyncOperation(); | ||
_ = theField.Value; // Compliant, unknown | ||
|
||
theField = 42; | ||
await AnAsyncOperation(); | ||
_ = theField.Value; // Compliant, unknown | ||
|
||
theField = null; | ||
await AnotherAsyncOperation(theField.Value); // Noncompliant, empty | ||
_ = theField.Value; // Compliant, unknown | ||
|
||
theField = null; | ||
await AnAsyncOperation(); | ||
_ = theField.Value; // Compliant, yield break above stops execution | ||
|
||
async Task<int> AnAsyncOperation() => await Task.FromResult(42); | ||
async Task<int> AnotherAsyncOperation(int i) => await Task.FromResult(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.
Add tests where the task is created before the the assignment:
var task = AnAsyncOperation();
theField = null;
await task;
_ = theField.Value;
08ef95f
to
56b4f16
Compare
50d2b5e
to
29ba312
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.
LGTM
|
||
theField = null; | ||
yield break; | ||
_ = theField.Value; // Compliant, yield break above stops execution |
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.
Here you can use "unreachable" 😄
56b4f16
to
84bf1c2
Compare
e41d4ac
to
0d1fa32
Compare
84bf1c2
to
9b2a752
Compare
0d1fa32
to
158e2a7
Compare
9b2a752
to
37dd64c
Compare
1f63918
to
ae2baec
Compare
ae2baec
to
e1f168f
Compare
Kudos, SonarCloud Quality Gate passed! |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Part 3 of task 6 of #6794
Previous task: #6967