-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Milestone
Description
Championed issue: dotnet/csharplang#4334
Spec: https://github.com/dotnet/csharplang/blob/master/proposals/csharp-10.0/record-structs.md
Relates to parameterless ctor and field initializers in structs: dotnet/csharplang#99
Compiler
- Syntax tests
- 'record' 'struct'
- 'record' 'class'
- Appropriate language version checks are in place
- Etc.
- Type kind, validate Record Struct is a struct and has treatment appropriate to a struct
- 'default'
- Creation
- Generic constraint checks (see
TypeDeclaration_IsStruct_InConstraints,TypeDeclaration_IsStruct_Unmanaged) - Derives from ValueType (see
TypeDeclaration_IsStruct) - Etc.
- Record struct members
- A member named "Clone" is disallowed (see
Clone_DisallowedInSource) - A field inside a Record Struct cannot have an unsafe type (see
RestrictedTypesAndPointerTypes) - Destructors are not allowed (see
TypeDeclaration_NoDestructor) - Equality members (explicit declaration / implicit declaration and code generation)
-
Equalsfor this type (seeEquality_xy) -
Equalsforobjecttype (seeEquality_01andObjectEquals_06for user-defined) -
GetHashCode(seeRecordEquals_xy,GetHashCode_UserDefined -
==and!=operators for this type (seeEqualityOperators_xy)
-
- Printing members (explicit declaration / implicit declaration and code generation)
-
PrintMembers -
ToString
-
- Primary Constructor
- Parameter-less Primary Constructor is disallowed (see
RecordProperties_01_EmptyParameterList,TypeDeclaration_NoParameterlessConstructor,TypeDeclaration_NoInstanceInitializers) - Test a signature conflict with an explicitly declared constructor (see
RecordProperties_02) - Any user-defined constructor must have an explicit
thisconstructor initializer. (seeRecordProperties_02) - A warning is produced if a parameter of the primary constructor is not read. (see
RecordProperties_03) - The definite assignment rules for struct instance constructors apply to the primary constructor of record structs.
- XML Doc comments on the type declaration can be used to document parameters and can refer to the parameters (see
XmlDoc)
- Parameter-less Primary Constructor is disallowed (see
- Positional struct members
- Conditionally synthesized based on Primary Constructor's signature
- A public
getandinitauto-property is created if the record struct hasreadonlymodifier,getandsetotherwise. (seeRecordProperties_01_Readonly) - The auto-property is initialized to the value of the corresponding primary constructor parameter. (see
RecordProperties_01) - Attributes can be applied to the synthesized auto-property and its backing field by using property: or field: targets for attributes syntactically applied to the corresponding record struct parameter. (see
AttributesOnPrimaryConstructorParameters_01) - Etc.
- Deconstruct
- Synthesized for a positional record struct with at least one parameter, unless explicitly declared
- Instance field initializers
- Parameters of the primary constructor as well as members of the record struct are in scope within initializers of instance fields or properties. Instance members would be an error in these locations
- If there is a Primary Constructor, only the primary constructor executes the instance initializers appearing in the record-struct-body.
- If there is no primary constructor, the instance initializers execute as part of the parameter-less constructor.
- We have an open design issue around instance initializers in record structs which we should close on, perhaps under umbrella of "Parameter-less struct constructors" feature.
- A member named "Clone" is disallowed (see
-
withexpression on structs- Test on regular struct instances
- Test in generic context on type parameters with appropriate constraints
- Allow user-defined positional members of records to be fields
- Appropriate language version checks are in place
- Etc.
- SemanticModel around new syntax
- IOperation around new syntax
- Analyzer actions around new syntax and new members
- SymbolDisplay
Work items
- parameters less primary constructor, including field initializers (tracking issue Allow parameterless constructors in record structs #52240)
- Consider improving parsing recovery of
struct Point(int x, int y); - Consider improving parsing error for
record interface C(int X, int Y);(RecordInterfaceParsing) - LDM: Emitting GetHashCode and Equals as
readonly(conditionally) (answer: yes, issue Record structs: emitreadonlymodifier for synthesized members #54419) -
leftandrightparameter names in equality/inequality operators (PR Merge latest bits from main into record-structs #52236) -
withon structs (PR Allow 'with' expression on value types #52319) - allowing record positional members to be implemented as fields (PR Records: allow positional members to be implemented with fields #52480)
- take C# 9 compat break on hidden positional members (tracking issue Records: Should produce an error when member we pick as positional member is hidden #52630)
-
withexpressions on anonymous types (PR Allowwithon anonymous types #53248) - SyntaxNormalizer
- public API: metadata scenario for
IsRecord(tracking issue ImplementIsRecordon record structs #52233, PR Record-structs: Address some PROTOTYPE markers #52256) - LDM: Should records implement
ISpanFormattable? (answer: no) - LDM: Should
ToString/PrintMembersuseInterpolatedStringBuilder? (discussion) (answer: no) - LDM: Confirm we'll allow parameterless primary constructor (answer: yes)
- LDM: What about initializers when no primary constructor? (question relates to parameterless constructors in structs)
- LDM: Confirm that
Equals(R)API doesn't needin(answer: we won't addinoverloads, too heuristic-dependant) - LDM: Confirm
withon generic structs (did we have LDM notes and/or decision already? current behavior is fine ) - LDM: Confirm whether
GetHashCodeshould include a hash of the type (this isn't needed per email thread, current behavior is fine) - LDM: Confirm whether property should come first, or field from current type should come before property from base
- remove PROTOTYPE markers
- EnC: EnC: support for record structs #51200
Productivity
- completion (done in Recommend struct and class keywords after record #51304)
- formatting
- Intellisense
- QuickInfo (PR Record-structs: adjust symbol display and QuickInfo #52455)
- Should appear correctly in solution explorer. (see Fix graph query for records #48451 where this was done for C# 9.0 records)
- Also name suggestion for positional parameters should be PascalCased. (see Treat record positional parameters as properties #48329)
- Also destructor intellisense. (see Add destructor intellisense test for record #48297)
- Also navigation. (see Add records support in navigate to #48116)
- Make type abstract. (see Extend make type abstract to include records #48227)
- FAR works like for record classes
- record structs in help service (similar to F1 help for private protected and protected internal go to their expected places #46343)
- Complete statement command will need to handle the new RecordStructDeclarationSyntax node. (see Support abstract methods and records in complete statement command #48128)
- CodeLens support (issue Add support for record structs in CodeLens #52430)
- GoToTypes support (issue "Go to all" and "Go to types" don't work for records #51672)
- Make sure that explicit
PrintMembersisn't reported as unused by IDE analyzers. See PrintMembers method in record is unused #52421 - attribute target completion (see issue Completion don't provide property target in record parameter #51756)
- Add ConvertTupleToRecordStruct
- IDE to handle xml docs (PR Handle records in documentation comments in IDE side #52737 for records)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done Umbrellas