-
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
Span<T> == null throws ArgumentNullException #20457
Comments
@jaredpar, this is a bit strange. Is there anything we can do about it? |
CC @gafter who can discuss the best pattern to use here. |
@gafter, any pointers? |
ping @gafter |
I suggest adding [Obsolete("Incorrect equality test; Span<T> is a value type", true)]
public static bool operator ==(Span<T> left, T[] right) => true;
[Obsolete("Incorrect equality test; Span<T> is a value type", true)]
public static bool operator !=(Span<T> left, T[] right) => false; |
This PR fixes the issue (by adding a null check to the implicit cast): dotnet/corefx#25257
Should we still add those equality overloads? |
I don't think so. However, it is slightly strange that you can convert a null |
I know it doesn't make sense to compare it to null since it is a struct. But it is allowed since we have a implicit cast operator that get called, op_Implicit(T[] array).
And that operator throws the exceptions when calling the constructor:
Repro:
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Span`1.op_Implicit(T[] array)
at ConsoleApp1.Program.Main(String[] args)
The text was updated successfully, but these errors were encountered: