Skip to content

[Version 10.0] Feature support for record with sealed ToString#1550

Draft
RexJaeschke wants to merge 2 commits into
draft-10from
v10-record-with-sealed-ToString
Draft

[Version 10.0] Feature support for record with sealed ToString#1550
RexJaeschke wants to merge 2 commits into
draft-10from
v10-record-with-sealed-ToString

Conversation

@RexJaeschke

Copy link
Copy Markdown
Contributor

There is no corresponding MS proposal.

This PR builds on V9's PR #1458, which as of this time has not been reviewed, and changes during its adoption may impact this PR.

@RexJaeschke RexJaeschke added this to the C# 10 milestone Jan 24, 2026
@RexJaeschke RexJaeschke added type: feature This issue describes a new feature Review: pending Proposal is available for review labels Jan 24, 2026
@RexJaeschke
RexJaeschke marked this pull request as draft January 24, 2026 16:14
@jnm2

jnm2 commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

The proposal exists as dotnet/csharplang#4174. I would be happy to review this, as the original author.

@RexJaeschke
RexJaeschke requested a review from jnm2 January 26, 2026 17:40
Comment thread standard/classes.md
```

The method may be declared explicitly. It is an error if the explicit declaration does not match the expected signature or accessibility, or if the explicit declaration doesn't allow overriding it in a derived type and the record class type is not sealed. It is an error if either synthesized, or explicitly declared, method doesn't override `object.ToString()` (for example, due to shadowing in intermediate base types).
The method may be declared explicitly. It is an error if the explicit declaration does not match the expected signature or accessibility. It is an error if either synthesized, or explicitly declared, method doesn't override `object.ToString()` (for example, due to shadowing in intermediate base types).

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 removed statement is a consequence of the requirement that the member overrides object.ToString().

Suggested change
The method may be declared explicitly. It is an error if the explicit declaration does not match the expected signature or accessibility. It is an error if either synthesized, or explicitly declared, method doesn't override `object.ToString()` (for example, due to shadowing in intermediate base types).
The method may be declared explicitly. It is an error if either synthesized, or explicitly declared, method doesn't override `object.ToString()` (for example, due to shadowing in intermediate base types).

Comment thread standard/classes.md
The method may be declared explicitly. It is an error if the explicit declaration does not match the expected signature or accessibility, or if the explicit declaration doesn't allow overriding it in a derived type and the record class type is not sealed. It is an error if either synthesized, or explicitly declared, method doesn't override `object.ToString()` (for example, due to shadowing in intermediate base types).
The method may be declared explicitly. It is an error if the explicit declaration does not match the expected signature or accessibility. It is an error if either synthesized, or explicitly declared, method doesn't override `object.ToString()` (for example, due to shadowing in intermediate base types).

Sealing an explicitly declared `ToString` method prevents the compiler from synthesizing a `ToString` method for any derived record types. However, this does not prevent the compiler from synthesizing `PrintMembers`.

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.

Should this be a note?

@BillWagner
BillWagner force-pushed the v10-record-with-sealed-ToString branch from 6d786ac to 8befc03 Compare March 24, 2026 19:32
@BillWagner
BillWagner force-pushed the v10-record-with-sealed-ToString branch from 8befc03 to 9ffa65f Compare April 14, 2026 21:28
@BillWagner
BillWagner force-pushed the v10-record-with-sealed-ToString branch from 9ffa65f to df28094 Compare May 13, 2026 14:45
RexJaeschke and others added 2 commits June 24, 2026 14:58
@BillWagner
BillWagner force-pushed the v10-record-with-sealed-ToString branch from df28094 to e8f79d1 Compare June 24, 2026 18:58
@BillWagner

Copy link
Copy Markdown
Member

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