-
Notifications
You must be signed in to change notification settings - Fork 92
[Version 10.0] Feature support for record with sealed ToString #1550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
RexJaeschke
wants to merge
2
commits into
draft-10
Choose a base branch
from
v10-record-with-sealed-ToString
base: draft-10
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -422,7 +422,7 @@ | |
| : 'where' type_parameter ':' type_parameter_constraints | ||
| ; | ||
|
|
||
| type_parameter_constraints | ||
| : primary_constraint (',' secondary_constraints)? (',' constructor_constraint)? | ||
| | secondary_constraints (',' constructor_constraint)? | ||
| | constructor_constraint | ||
|
|
@@ -534,15 +534,15 @@ | |
| > static void M() | ||
| > { | ||
| > // nonnull constraint allows nonnullable struct type argument | ||
| > A<int> x1; | ||
| > // possible warning: nonnull constraint prohibits nullable struct type argument | ||
| > A<int?> x2; | ||
| > // nonnull constraint allows nonnullable class type argument | ||
| > A<C> x3; | ||
| > // possible warning: nonnull constraint prohibits nullable class type argument | ||
| > A<C?> x4; | ||
| > // nonnullable base class requirement allows nonnullable class type argument | ||
| > B1<C> x5; | ||
| > // possible warning: nonnullable base class requirement prohibits nullable | ||
| > // class type argument | ||
| > B1<C?> x6; | ||
|
|
@@ -3556,7 +3556,7 @@ | |
| > static void Main() | ||
| > { | ||
| > field = 10; | ||
| > Console.WriteLine(Property); // Prints 10 | ||
| > Property = 20; // This invokes the get accessor, then assigns | ||
| > // via the resulting variable reference | ||
| > Console.WriteLine(field); // Prints 20 | ||
|
|
@@ -4917,7 +4917,7 @@ | |
| : '!' | ||
| ; | ||
|
|
||
| overloadable_unary_operator | ||
| : '+' | '-' | logical_negation_operator | '~' | '++' | '--' | 'true' | 'false' | ||
| ; | ||
|
|
||
|
|
@@ -6134,7 +6134,7 @@ | |
| > public static bool operator!=(R1? left, R1? right) => !(left == right); | ||
| > | ||
| > public override int GetHashCode() | ||
| > { | ||
| > return HashCode.Combine(EqualityComparer<Type>.Default.GetHashCode(EqualityContract), | ||
| > EqualityComparer<T1>.Default.GetHashCode(P1)); | ||
| > } | ||
|
|
@@ -6245,7 +6245,9 @@ | |
| public override string ToString(); | ||
| ``` | ||
|
|
||
| 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`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a note? |
||
|
|
||
| The synthesized method: | ||
|
|
||
|
|
@@ -6315,7 +6317,7 @@ | |
| > protected virtual bool PrintMembers(StringBuilder builder) | ||
| > { | ||
| > builder.Append(nameof(P1)); | ||
| > builder.Append(" = "); | ||
| > builder.Append(this.P1); // or builder.Append(this.P1.ToString()); if P1 has a value type | ||
| > return true; | ||
| > } | ||
|
|
@@ -6346,11 +6348,11 @@ | |
| > builder.Append(", "); | ||
| > } | ||
| > builder.Append(nameof(P2)); | ||
| > builder.Append(" = "); | ||
| > builder.Append(this.P2); // or builder.Append(this.P2); if P2 has a value type | ||
| > builder.Append(", "); | ||
| > builder.Append(nameof(P3)); | ||
| > builder.Append(" = "); | ||
| > builder.Append(this.P3); // or builder.Append(this.P3); if P3 has a value type | ||
| > return true; | ||
| > } | ||
|
|
@@ -6483,6 +6485,3 @@ | |
| > ``` | ||
| > | ||
| > *end example* | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
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().