Skip to content
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

Test plan for "record structs" #51199

Closed
80 of 92 tasks
jcouv opened this issue Feb 12, 2021 · 11 comments
Closed
80 of 92 tasks

Test plan for "record structs" #51199

jcouv opened this issue Feb 12, 2021 · 11 comments
Assignees
Labels
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented Feb 12, 2021

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

@jcouv jcouv added this to the C# 10 milestone Feb 12, 2021
@jcouv jcouv self-assigned this Feb 12, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Feb 12, 2021
@Youssef1313
Copy link
Member

Have the implementation of the feature started?

@jcouv
Copy link
Member Author

jcouv commented Feb 13, 2021

It's about to

@jaredpar jaredpar added Feature Request and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 16, 2021
@Youssef1313
Copy link
Member

Youssef1313 commented Feb 18, 2021

Posting few things that are easy to forget:

[jcouv: thanks for the scenarios. I moved them into OP]

@jcouv
Copy link
Member Author

jcouv commented Apr 3, 2021

PR #52261 added the coverage and fixes suggested by @Youssef1313. Thanks!
I'll do some manual validation in next few days.

@Youssef1313
Copy link
Member

Youssef1313 commented Apr 6, 2021

One more minor scenario:
[jcouv: thanks for the scenario. I moved it into OP]

@Youssef1313
Copy link
Member

Youssef1313 commented Apr 7, 2021

Moved to OP.

@Youssef1313
Copy link
Member

Youssef1313 commented Apr 17, 2021

@jcouv
Copy link
Member Author

jcouv commented Apr 17, 2021

@Youssef1313 MakeTypeAbstract is "done" because a test was added, but purposefully not supporting because structs can't be abstract.

@Youssef1313
Copy link
Member

@jcouv Can you add handling record structs in help service to the original issue? This is something that should be done a little bit late (after a doc page is created in dotnet/docs with f1_keywords recordstruct_CSharpKeyword). This will be similar to #46343. Thanks.

@jcouv
Copy link
Member Author

jcouv commented Apr 30, 2021

@Youssef1313 Added. Thanks

@jcouv
Copy link
Member Author

jcouv commented Sep 23, 2021

Remaining issues are tracked as separate issues (linked). I'll go ahead and close this.

@jcouv jcouv closed this as completed Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done Umbrellas
Development

No branches or pull requests

4 participants