Skip to content

Test plan for "required members" #57046

@jcouv

Description

@jcouv

Championed proposal: dotnet/csharplang#3630
Specification: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/required-members.md

Compiler

declaration

  • required as contextual keyword ("required" type, type parameter, etc exists in scope)
  • where required modifier is allowed/disallowed
  • disallow required modifier based on LangVer
  • disallow required type name based on LangVer
  • missing attribute type or ctor
  • RequiredMember attribute emitted on type and members
  • Overriding can tighten requirement
  • Cannot hide required member
  • Required member must as accessible as containing type
  • RequiredMember attribute disallowed in source
  • field/property without setter
  • field/property with less accessible setter
  • different kinds of members (field, property, indexer, event, nested type, ...)
  • different kinds of containing types (class, struct, record; disallow interface)
  • required with field/property initializer (allowed)
  • rules with obsolete
  • no definite assignment for SetsRequired
  • must specify SetsRequired when SetsRequired on base or this
  • combination with other modifiers (fixed, ref readonly, ref, const, static disallowed; others such as extern, partial, virtual allowed)
  • record with required positional member declared explicitly
  • modifier can be parsed in different orders

metadata

  • Required attribute cannot be manually applied
  • required members are marked Required and the type too. But not if merely derived from a type with required members.
  • CompilerFeatureRequired with marker string
  • Obsolete with marker string
  • invalid type from metadata
  • SetsRequired set on record copy ctor

usage

  • object initialization
  • nested object initializers new C { Inner = new D { ... } } versus new C { Inner = { ... } }
  • attribute construction with named arguments
  • new() constraint not satisfied

nullability

  • nullable analysis of constructors in presence or absence of [SetsRequiredMembers] with required members
  • initial nullable flow state of required setters, when the type contains some combination of required and non-required non-nullable reference properties.

LDM

  • LDM: should we give a diagnostic for required property with an initializer (useless)? (answer: no, can be useful)
  • LDM: should we do something about ref-returning properties (useless)? (disallow)
  • LDM: should we do something about readonly modifier? (disallow)
  • LDM: what if the required property is obsolete?

BCL

Productivity:

  • typing/completion
  • override completion
  • MetadataAsSource (done)
  • formatting
  • colorization
  • F1/help (done)
  • QuickInfo (P0: should not crash, P2: consider whether to show required) (no change, manually verified)
  • Sorting modifiers (done)
  • completion of object creation should call out required members
  • snippet-style completion?
  • some existing refactorings produce/modify constructors
  • add option to generate required property for refactorings that generate properties

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Language/design

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions