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

S3655: Fields with methods, local functions, yield and async #6981

Merged
merged 3 commits into from
Mar 28, 2023

Conversation

antonioaversa
Copy link
Contributor

Part 3 of task 6 of #6794

Previous task: #6967

@antonioaversa antonioaversa changed the title S3655: Test mutable fields with methods, local functions, yield and async S3655: Test fields with methods, local functions, yield and async Mar 23, 2023
@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-3 branch from 2d46646 to d20bcf2 Compare March 23, 2023 13:33
@antonioaversa antonioaversa changed the title S3655: Test fields with methods, local functions, yield and async S3655: Fields with methods, local functions, yield and async Mar 23, 2023
@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-3 branch from d20bcf2 to 50d2b5e Compare March 24, 2023 12:43
@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-2 branch from f7893e0 to 08ef95f Compare March 24, 2023 12:43

theField = null;
_ = theField.Value; // Noncompliant, empty
_ = theField.Value; // Compliant, when reached the ".Value" above implies aField is not null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_ = 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

Comment on lines 767 to 850
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);
}
Copy link
Contributor

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;

@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-2 branch from 08ef95f to 56b4f16 Compare March 27, 2023 07:35
@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-3 branch from 50d2b5e to 29ba312 Compare March 27, 2023 07:35
Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-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


theField = null;
yield break;
_ = theField.Value; // Compliant, yield break above stops execution
Copy link
Contributor

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" 😄

@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-2 branch from 56b4f16 to 84bf1c2 Compare March 27, 2023 15:28
@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-3 branch from e41d4ac to 0d1fa32 Compare March 27, 2023 15:28
@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-2 branch from 84bf1c2 to 9b2a752 Compare March 28, 2023 12:41
@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-3 branch from 0d1fa32 to 158e2a7 Compare March 28, 2023 12:41
@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-2 branch from 9b2a752 to 37dd64c Compare March 28, 2023 14:05
Base automatically changed from Antonio/S3655-cs9-cs10-syntax-step6-2 to feature/SE March 28, 2023 14:45
@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-3 branch from 1f63918 to ae2baec Compare March 28, 2023 14:47
@antonioaversa antonioaversa marked this pull request as ready for review March 28, 2023 14:48
@antonioaversa antonioaversa force-pushed the Antonio/S3655-cs9-cs10-syntax-step6-3 branch from ae2baec to e1f168f Compare March 28, 2023 15:05
@sonarcloud
Copy link

sonarcloud bot commented Mar 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 Mar 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
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants