SentinelMethod.Equals should return reference equality#34380
SentinelMethod.Equals should return reference equality#34380benaadams wants to merge 1 commit intodotnet:masterfrom
Conversation
10ece32 to
6848d0b
Compare
stephentoub
left a comment
There was a problem hiding this comment.
Why are all of these overrides needed at all?
Ati liked to write code this way. It is trying to ensure that somebody is not calling methods on the sentinel by accident, etc. |
|
I am wondering whether this is an early red flag that the CoreCLR I think the |
If the instance is exposed, though, which it would seem to be given the break (?), that seems like something that should be fixed so that the methods do something reasonable if they are used. Throwing a null ref isn't particularly friendly. At the very least they should throw not supported or something like that, no? |
Or maybe abandon the idea of trying to "fix" |
It depends on style you prefer. My style would be to have these safety overrides in debug build only with asserts, and not compile them into release at all. |
|
Can still fix it for |
|
Also isn't having a broken |
That sounds fine to me. |
They are abstract method implementations which makes that trickier :-/ |
|
Not sure what next steps are here? |
|
e.g. could change the checks to public static bool operator ==(MethodInfo left, MethodInfo right)
{
// Test "right" first to allow branch elimination when inlined for null checks (== null)
// so it can become a simple test
if (right is null)
{
return (left is null) ? true : false;
}
if (ReferenceEquals(left, right))
{
return true;
}
return (left is null) ? false : left.Equals(right);
} |
|
Yes, I think that would work. Also, I would change ReferenceEquals to |
|
Going to close this one |
Seen in #34375 (comment)
Blocking update of coreclr update in corefx
With "Support faster null checks" dotnet/coreclr#21765 the .Equals override gets called so it should test since its overriden (or not be overriden); rather than just
throw null/cc @steveharter @jkotas @stephentoub