Skip to content

Test plan for parameterless struct constructors #51698

@cston

Description

@cston

Proposal: parameterless-struct-constructors.md
Branch: features/struct-ctors

  • -langversion:
    • for parameterless ctor (see PublicParameterlessConstructor)
    • for field initializers (see FieldInitializers_01)
  • public and non-public ctors declared in source (see PublicParameterlessConstructor vs. NonPublicParameterlessConstructor_01)
  • extern and unsafe are valid ctor modifiers
  • : this() and : base() initializers:
    • : base() initializer disallowed
    • : this() initializer allowed from other ctors (see ThisInitializer_01)
    • : this(arg0, ...) initializer allowed from parameterless ctor (see ThisInitializer_02)
  • record struct parameterless ctor must include : this(arg0, ...) (see TypeDeclaration_ParameterlessConstructor_OtherConstructors)
  • default ignores parameterless ctor
  • new() invokes parameterless ctor:
    • from new S() and new S { ... } (see PublicParameterlessConstructor)
    • from new S() and new S { ... } in expression tree (see ExpressionTrees)
    • from new T() with where T : struct and where T : new() (see PublicParameterlessConstructor)
  • all fields assigned:
    • all fields have initializers if any have initializers and no ctors (see FieldInitializers_01 and FieldInitializers_02)
    • all fields have initializers or are explicitly assigned in each explicit ctor (see FieldInitializers_01 and FieldInitializers_02)
  • field initializers and initialization order with:
    • no constructors (see FieldInitializers_None)
    • explicit parameterless ctor (see FieldInitializers_None)
    • explicit ctor with parameters (see FieldInitializers_None)
    • explicit ctor with : this() initializer with/without parameterless ctor (see ThisInitializer_03)
    • explicit parameterless ctor with : this(arg0, ...) initializer (see ThisInitializer_03)
  • field initializers and initialization order on record struct with cases above and: (see TypeDeclaration_ParameterlessConstructor_Initializers)
    • no ()
    • ()
    • (arg0, ...)
  • nullability analysis (initial state of fields in ctor bodies) for field initializer cases above (see NullableAnalysis_*)
  • error for new S() in parameter default value if S has parameterless ctor (see ParameterDefaultValues_*)
  • analyzer checks runtime capability and warns for new T() with where T : struct or where T : new() on desktop framework: dotnet/roslyn-analyzers/issues/5272

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Active/Investigating

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions