-
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
Warning not provided for obsolete method ReadOnlySpan.Equals #111166
Comments
It looks like the behavior is "By Design", obsolete state of a method is determined based on the least overridden declaration (Object.Equals in this case). There is a comment in
Compiler also reports a warning when an Obsolete attribute is placed on an override:
Also, apparently the ReadOnlySpan.Equals implementation violates the following rule:
I am not sure why framework decided to ignore all the "red" flags and applied the Obsolete attribute despite the fact that its presence does not make a difference. Since a span cannot be be boxed, it feels like always returning |
@AlekseyTs Thanks for the thorough explanation. Can this issue be forwarded to the team that maintains the framework to see if there is any room for improvement? |
Transferring to runtime |
CC @stephentoub |
In my opinion, it doesn't make a difference that people usually expect from an Obsolete attribute. And it doesn't prevent a user code from running into a completely unnecessary (again, in my opinion) exception at runtime. |
The idea is that usage of the method is illogical. As ref structs can’t be boxed, the user either knows the type (of at least that it could be a ref struct in a generic), and, in both those situations, I do agree with @AlekseyTs though that such a decision goes against the grain of other BCL decisions. An analyzer alone (or the obsolete marker) should’ve been enough. |
Perhaps I am missing something, but returning |
Apparently not in Visual Studio Code - see the screenshot in my original post. I will submit another issue about this to the right repo. But even if it shows up in formatting, it's not as helpful as a compiler warning, which is the usual expectation for obsolete methods. It's not possible to fail a CI build because of formatting, but it is possible to fail a CI build because of a compiler warning.
Programmers cannot be trusted to always make logical decisions - that is what compilers are for.
If CS0618 cannot cover this case then a new analyzer would definitely be welcome.
That would be consistent with |
Tagging subscribers to this area: @dotnet/area-system-runtime |
Version Used:
Steps to Reproduce:
git clone https://github.com/sweemer/ReadOnlySpanEquals.git
cd ReadOnlySpanEquals && dotnet run
Unhandled exception. System.NotSupportedException: Equals() on Span and ReadOnlySpan is not supported. Use operator== instead.
Diagnostic Id: CS0618
Expected Behavior: Warning shown when building project.
Actual Behavior: No warning shown, only runtime exception thrown.
Note that IntelliSense in Visual Studio Code correctly flags this method as deprecated, but no warning is shown.
The text was updated successfully, but these errors were encountered: