Open jhinder opened 5 years ago
According to the language specification, the invocation binds to the original method, not the override. Since the original method is not obsolete, no warning is given.
This footgun is now at least documented correctly. But I would like to see the restriction lifted, per my earlier comment in the linked issue:
My use-case is to indicate that the "general"
object.Equals(object?)
overload shouldn't be used because, to preserve commutativity, it only mimics theIEquatable<TSelf>.Equals
overload, and not the additionalIEquatable<int>.Equals
overload—that is,instance.Equals(1)
may resolve to the wrong overload and always returnfalse
.
It's also already used in the BCL: for Span<T>
/ReadOnlySpan<T>
, HashCode
, NonCryptographicHashAlgorithm
, and this mock struct (all Equals
and/or GetHashCode
), and for PasswordDeriveBytes.GetBytes
. It looks like VectorSpan<T>
/ReadOnlyVectorSpan<T>
copied Span<T>
and will have it too.
Version Used: VS 16.0 Preview 2
Steps to Reproduce:
Expected Behavior: The call to
M
will result in a warning about using an obsolete member.Actual Behavior: QuickInfo will show "[deprecated]" for
Derived.M()
, but no warning is emitted for the call.This is important for
Span<T>
, which overridesEquals
andGetHashCode
. Both of those are guaranteed to throw, and the obsoletion attribute of these methods contains important information about using these methods (e.g. to use==
instead ofEquals
).