-
Couldn't load subscription status.
- Fork 4.2k
Add regression tests for Interlocked.Exchange with null checks #80802
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: CyrusNajmabadi <[email protected]>
|
@dotnet/roslyn-compiler ptal. |
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.
The "likely by 43536" mentioned in copilot's message also appears to be a hallucination; yes, that issue is related to nullable, but is unrelated to ref parameters.
| Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(15, 20)); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75993")] |
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.
75993 is a merge PR from 17.12 to 17.13. What is the real bug?
| Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(15, 20)); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75993")] |
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.
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75993")] | |
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51191")] |
| comp.VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75993")] |
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.
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75993")] | |
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51191")] |
| comp.VerifyDiagnostics(); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75993")] |
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.
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/75993")] | |
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51191")] |
| var comp = CreateCompilation(source); | ||
| comp.VerifyDiagnostics(); |
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.
| var comp = CreateCompilation(source); | |
| comp.VerifyDiagnostics(); | |
| CreateCompilation(source).VerifyDiagnostics(); |
| var comp = CreateCompilation(source); | ||
| comp.VerifyDiagnostics(); |
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.
| var comp = CreateCompilation(source); | |
| comp.VerifyDiagnostics(); | |
| CreateCompilation(source).VerifyDiagnostics(); |
| var comp = CreateCompilation(source); | ||
| comp.VerifyDiagnostics(); |
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.
| var comp = CreateCompilation(source); | |
| comp.VerifyDiagnostics(); | |
| CreateCompilation(source).VerifyDiagnostics(); |
Summary
Adds regression tests for issue #51191 to ensure that
Interlocked.Exchangeand related methods don't produce false nullable warnings when used with null arguments after null checks.Background
Issue #51191 reported that the following pattern was incorrectly producing CS8625 warnings:
This issue has been resolved (likely by #43536 which fixed type inference for ref parameters to use R-value types). These tests ensure the behavior doesn't regress.
Changes
Added three comprehensive tests to
NullableReferenceTypesTests.cs:InterlockedExchange_WithNullCheckAndNullArgument: Tests the exact scenario from the issue - using
Interlocked.Exchangewith a null argument after verifying the field is not null.InterlockedCompareExchange_WithNullCheckAndNullArgument: Verifies the same behavior works correctly for
Interlocked.CompareExchange.InterlockedExchange_WithExplicitTypeArgument: Tests the scenario where the nullable type argument is explicitly specified (e.g.,
Exchange<C?>).All tests verify that no nullable warnings are produced in these common scenarios.
Fixes #51191
Original prompt
Fixes #51191
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.