-
Notifications
You must be signed in to change notification settings - Fork 6k
Update CS0460 documentation to include C# 8/9 constraint exceptions #46528
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
Conversation
Co-authored-by: BillWagner <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @copilot
I have a few suggestions, and then this is ready.
…fix code sample Co-authored-by: BillWagner <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot made all the changes I requested in my review. This is ready for a final human review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the CS0460 error documentation to accurately reflect the exceptions introduced in C# 8 and C# 9 regarding constraint specifications on override and explicit interface implementation methods.
- Updated metadata (ms.date, ai-usage)
- Added sections explaining C# 8 and C# 9 exceptions with corresponding sample code
- Revised example code to differentiate between error and valid usage scenarios
Co-authored-by: gewarren <[email protected]>
Head branch was pushed to by a user without write access
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
The CS0460 compiler error documentation was outdated and didn't reflect the constraint exceptions introduced in C# 8 and C# 9. The existing documentation stated that constraints cannot be specified directly on override and explicit interface implementation methods, but this is no longer entirely accurate.
Changes Made
default
constraint, which can be applied to resolve ambiguities with nullable reference typeswhere T : class
andwhere T : struct
constraints to allow annotations for type parameters constrained to reference typesExample
The updated documentation now shows that while this still generates CS0460:
These are now valid since C# 8 and C# 9:
Fixes #46009.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Internal previews