Skip to content

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

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

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

Conversation

@RexJaeschke
Copy link
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
Copy link
Contributor

jnm2 commented Jan 26, 2026

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
```

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
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).

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
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?

Remove unnecessary blank lines from classes.md
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

Comments