-
Notifications
You must be signed in to change notification settings - Fork 789
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
(=) and (<>) throw NullReferenceExceptions when left operand is null #3108
Comments
this sounds like we don't have property-based tests for this ;-( |
I think it's always been like this. TBH the use of |
@dsyme - sure, agree that I'd never expect anything from {{Unchecked.defaultof}} to be a sane instance, however just using to show the issue succinctly and create a null instance here. The main issue I suspect here is one of interop, particularly with C# where having null references floating around is fairly 'usual'. |
Seems to work fine with C# types:
I think what @dsyme is saying is that if you need to use |
To be honest this is completely fine with the "fail-fast" principle. My first impression was that is should handle The only case which maybe could be allowed is that we don't fail when comparing with Triggering this means your interop layer didn't catch a null and converted it properly. |
I suppose it depends on how "legit" you consider null handling in F# code... Another case in which this can be an issue is from code interoperating with F#, for example:
Which, again due to F#s questionable interop story (in this case for Perhaps these are unreasonable assumptions about how gracefully F# should interop / interact with nulls - however it feels like a very small change that would not only increase consistency (i.e. by making Also, to further add to the confusion, this works 'as expected' for |
Closing this in favor of the Nullable Reference Types spec: #3108 This is, I'd argue, an expected oddity that if not changed in the core library, should be considered in nullability warnings with the feature. |
(=) and (<>) operators handle left operand being null incorrectly - throwing a NullReferenceException.
This is particularly unexpected, and makes these operators non-reflexive.
Repro steps
Expected behavior
(=) and (<>) operators should be reflexive.
Actual behavior
When the left operand of / first argument to the operator is null, a NullReferenceException is thrown.
Known workarounds
System.Object.Equals has the expected behaviour as described above.
Related information
Provide any related information
The text was updated successfully, but these errors were encountered: