-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
API Proposal: Unsafe.IsNullRef(ref readonly) #73608
Comments
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices Issue DetailsBackground and motivationCurrently we cannot test whether a ref readonly is null ref or not because Unsafe.IsNullRef() takes a ref parameter instead of ref readonly parameter. API Proposalnamespace System.Runtime.CompilerServices;
public static class Unsafe
{
- public bool IsNullRef(ref value);
+ public bool IsNullRef(ref readonly value); // or in value
} API Usageref readonly int Foo() {…}
ref readonly int x = ref Foo();
Unsafe.IsNullRef(in x); Alternative DesignsNo response RisksNo response
|
@hez2010 , you can but with a bit more verbose code: ref readonly int x = ref Foo();
Unsafe.IsNullRef(ref Unsafe.AsRef(in x)); |
The language doesn't currently support that, changing the current signature to in instead of ref would be breaking, and we can't overload on ref vs in. This would require dotnet/csharplang#6010, at which point there are a bunch of methods including this one we'd be looking to change over. |
Superseded by #73608. |
I think you mean by #85911? |
Background and motivation
Currently we cannot test whether a ref readonly is null ref or not because Unsafe.IsNullRef() takes a ref parameter instead of ref readonly parameter.
Given that Unsafe.IsNullRef doesn’t need mutability, the signature should be changed from IsNullRef(ref) to IsNullRef(ref readonly).
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: