Skip to content

Test plan for "record structs" #51199

@jcouv

Description

@jcouv

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)
      • Equals for this type (see Equality_xy)
      • Equals for object type (see Equality_01 and ObjectEquals_06 for user-defined)
      • GetHashCode (see RecordEquals_xy, GetHashCode_UserDefined
      • == and != operators for this type (see EqualityOperators_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 this constructor initializer. (see RecordProperties_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)
    • Positional struct members
      • Conditionally synthesized based on Primary Constructor's signature
      • A public get and init auto-property is created if the record struct has readonly modifier, get and set otherwise. (see RecordProperties_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.
  • with expression 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

Productivity

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done Umbrellas

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions