Fix incorrect statement about generic interface inheritance requiring covariance #48862
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #43518
The documentation contained a false statement claiming that generic interfaces can only inherit from non-generic interfaces if the generic interface is covariant. This is incorrect—any generic interface can inherit from a non-generic interface regardless of variance.
What Was Wrong
The original text stated:
This is demonstrably false. Generic interfaces can inherit from non-generic interfaces whether they are covariant, contravariant, or invariant. The inheritance has no variance requirement.
What Changed
The corrected text now:
object
in the overridden membersT
replacesobject
specifically in output positions (return types and property getters)T
is used only in output positions inIEnumerable<T>
, it can be marked as covariantT
were used in an input position in an overridden member, the interface couldn't be covariant, and the compiler would generate an errorThis correction incorporates the clarification provided by @BillWagner about how type parameters replace
object
in overridden members.Verification
Co-authored-by: BillWagner [email protected]
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.
Internal previews