Skip to content

[Version 9.0] Feature support for covariant return types#1462

Open
RexJaeschke wants to merge 7 commits intodraft-v9from
v9-covariant-return-types
Open

[Version 9.0] Feature support for covariant return types#1462
RexJaeschke wants to merge 7 commits intodraft-v9from
v9-covariant-return-types

Conversation

@RexJaeschke
Copy link
Contributor

This PR is my formal version of the corresponding MS spec.

The following issues are yet not handled by this PR and need to be addressed:

  1. 12.8.12.4 Indexer access: The MS spec states, “A similar change should be made in §12.8.12.4 Indexer access.” However, no proposed edits were given.
  2. 15.7.6 Virtual, sealed, override, and abstract accessors: The MS spec states, “We similarly permit override properties and indexers in interfaces as specified for classes in §15.7.6 Virtual, sealed, override, and abstract accessors.” However, no proposed edits were given.
  3. 19 Interfaces: The MS spec states, “We will need a rule that an explicit interface implementation must declare a return type no less derived than the return type declared in any override in its base interfaces.” However, no proposed edits were given.
  4. 19.6.5 interface mapping: The MS spec states, “This is technically a breaking change, … Due to this breaking change, we might consider not supporting covariant return types on implicit implementations.” We need to check if it’s supported.

@RexJaeschke RexJaeschke added this to the C# 9.0 milestone Nov 11, 2025
@RexJaeschke RexJaeschke marked this pull request as draft November 11, 2025 16:53
@RexJaeschke RexJaeschke mentioned this pull request Nov 11, 2025
18 tasks
@RexJaeschke RexJaeschke added type: feature This issue describes a new feature Review: work pending Review: pending Proposal is available for review and removed Review: work pending labels Nov 11, 2025
@BillWagner BillWagner self-assigned this Jan 16, 2026
Fill in the sections noted in the description of this PR.
@BillWagner BillWagner added the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Feb 2, 2026
@BillWagner BillWagner marked this pull request as ready for review February 2, 2026 19:22
@BillWagner
Copy link
Member

@jskeet This is ready for a first read.

Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parts about searching through classes and interfaces have lost me, but I suspect that's just my lack of concentration rather than a fault.

Respond to open comments, and perform a review.
@BillWagner
Copy link
Member

  • §19.6.2: Added "(if the member has a value return)" qualifier to the explicit interface implementation rule, preventing unsound ref return covariance.
  • §19.6.5: Added "if A has a value return" qualifier to the method matching rule, same ref-safety fix.
  • §12.6.2.2: Reworded interface parameter list text to say "most derived interface among the static type of the receiver and its direct and indirect base interfaces" — clarifying it refers to the interface hierarchy, not all implementors.
  • §15.7.6: Added informative note about the property type accessibility constraint, paralleling the note already in §15.6.5 for methods.
  • §19.6.5: Moved the covariant return type note from a standalone Note block into the "Notable implications" bullet list, matching jskeet's suggestion.
  • §12.8.10.1 : Added interface type-picking text to the returns-by-ref bullet for completeness (identity conversion only, no covariance for ref returns).
    -§15.7.6: Updated sealed property text to say "derived class or interface" for consistency.

I still need to investigate bullet 3 in Rex's notes above.

For bullet 4: This breaking change wasn't implemented. Rather, covariant return types on implicit interface implementations isn't supported (including by derived interfaces).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meeting: discuss This issue should be discussed at the next TC49-TG2 meeting Review: pending Proposal is available for review type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants