Skip to content

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

Draft
RexJaeschke wants to merge 7 commits into
draft-v9from
v9-covariant-return-types
Draft

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

Conversation

@RexJaeschke

Copy link
Copy Markdown
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
Comment thread standard/interfaces.md Outdated
@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
Copy Markdown
Member

@jskeet This is ready for a first read.

@jskeet jskeet left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread standard/classes.md
Comment thread standard/expressions.md Outdated
Comment thread standard/interfaces.md Outdated
Comment thread standard/interfaces.md Outdated
Comment thread standard/interfaces.md Outdated
@BillWagner

Copy link
Copy Markdown
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).

@BillWagner BillWagner removed the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Mar 11, 2026
@BillWagner
BillWagner force-pushed the v9-covariant-return-types branch from 797f25d to 14a92a1 Compare April 10, 2026 19:25
BillWagner added a commit that referenced this pull request Apr 10, 2026
…- 2 new commits

Delta: 2 commits (b37dedc Update classes.md, 30b3684 Review and update text)
Base: d68b04d (draft-v9 merge commit) / Original: 4e5e0a6 (alpha-v9)
Conflicts resolved: 2 in classes.md
  - Conflict 1: Kept 'do not' wording (contractions already expanded on alpha-v9)
  - Conflict 2: Merged covariant return type bullets (PR #1462) with new default constraint support (PR #1470)
@RexJaeschke
RexJaeschke marked this pull request as draft May 5, 2026 14:53
@BillWagner
BillWagner force-pushed the v9-covariant-return-types branch from 14a92a1 to 36f6616 Compare May 12, 2026 20:28
@BillWagner
BillWagner force-pushed the v9-covariant-return-types branch from 36f6616 to 530a3ca Compare June 24, 2026 17:42
@BillWagner

Copy link
Copy Markdown
Member

An earlier version of this feature is already present on alpha-v9 from a prior meeting. Edits made to this PR since then are not yet on alpha-v9; they will land at the next propagation. If you need them on alpha-v9 sooner, please open a separate PR targeting alpha-v9.
Thanks!

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

Labels

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