Skip to content

Test plan for "auto-default structs" #60167

@RikkiGibson

Description

@RikkiGibson

Spec: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/auto-default-structs.md
Championed proposal: dotnet/csharplang#5737

Compiler

  • add proposal to dotnet/csharplang (Create auto-default-structs.md csharplang#5964)
  • add to compiler test plan
  • -langversion
  • field initialization:
    • when all fields are explicitly assigned
    • when no fields are assigned (use initobj?)
      • implementation initializes each field individually.
    • when no fields
    • with auto-properties with get only; with set; with init
      • SemanticErrorTests.CS0843ERR_UnassignedThisAutoProperty,
      • FlowDiagnosticTests.AutoPropInitialization4
      • StructConstructorTests.FieldInitializers_08
    • with field-like events
    • when all sub-fields of a field are explicitly assigned
    • when some sub-fields of a field are explicitly assigned
    • when field is conditionally assigned
    • when explicitly calling declared constructor : this(...)
    • when explicitly calling default parameterless constructor : this()
    • when assigning this = default;
    • when assigning this = default; conditionally
    • when assigning to backing field of semi-auto property (i.e. using a field initializer) moved to Test plan for "field keyword in properties" #57012
    • when assigning to property of semi-auto property (i.e. in a constructor) moved to Test plan for "field keyword in properties" #57012
    • when reading field before assigning
  • fields assigned where C#10 produces warnings with /warn:5
  • record
    • with explicit fields
    • with explicit auto-properties
  • disabled-by-default diagnostics:
    • when all fields are explicitly assigned
    • when no fields are assigned
    • when diagnostics are elevated to warnings or errors
  • default assigned:
    • to backing fields of auto-properties
    • for field of type parameter type
    • for field of struct type with parameterless constructor
    • for field of empty struct type (no assignment?)
  • field initialization when parameters have !! (which runs first?)
  • nullable analysis treats auto-initialized fields as nullable
  • #pragma warning restore should not enable disabled diagnostics

Productivity

  • Add new error codes to UpgradeProject fixer
    • upgrade from warnings?
  • Debugger: reposition to first sequence point in constructor (init fields?)

Metadata

Metadata

Type

No type

Projects

Status

Language/design

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions