-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersFeature - Required MembersRequired properties and fieldsRequired properties and fields
Milestone
Description
Championed proposal: dotnet/csharplang#3630
Specification: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/required-members.md
Compiler
- Notify F#, C++/CLI, etc.
- VB (disallow attribute usage? tracking issue Required Members VB Support #61435)
- update test plan
- Review public API
- Any breaking changes? (parsing issues?)
- SyntaxNormalizer
- SymbolDisplay
- address PROTOTYPE markers
- local named "required" in top-level statements (C# 10 vs 11), will be handled as bug fix after merge (issue Local named "required" in top-level statements #61510)
- make type named "required" an error
- consider filtering
RequiredMembersattribute in compiler layer/API (issue Consider filteringRequiredMembersattribute in compiler layer/API #61511)
declaration
-
requiredas contextual keyword ("required" type, type parameter, etc exists in scope) - where
requiredmodifier is allowed/disallowed - disallow
requiredmodifier based on LangVer - disallow
requiredtype 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
-
RequiredMemberattribute 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)
-
requiredwith field/property initializer (allowed) - rules with obsolete
- no definite assignment for
SetsRequired - must specify
SetsRequiredwhenSetsRequiredonbaseorthis - combination with other modifiers (
fixed,ref readonly,ref,const,staticdisallowed; others such asextern,partial,virtualallowed) - record with required positional member declared explicitly
- modifier can be parsed in different orders
metadata
-
Requiredattribute cannot be manually applied -
requiredmembers are markedRequiredand the type too. But not if merely derived from a type with required members. -
CompilerFeatureRequiredwith marker string -
Obsoletewith marker string - invalid type from metadata
-
SetsRequiredset on record copy ctor
usage
- object initialization
- nested object initializers
new C { Inner = new D { ... } }versusnew 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
requiredproperty 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
readonlymodifier? (disallow) - LDM: what if the required property is obsolete?
BCL
- Confirm we want types in BCL and complete API review
- Implement types (Add attributes for required members runtime#64287)
- Can/should Reflection APIs honor
required?
Productivity:
- typing/completion
- Partial doesn't trigger soft select in override completion #61439 covers soft-select during override completion, also broken for partial.
- 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-CompilersFeature - Required MembersRequired properties and fieldsRequired properties and fields
Type
Projects
Status
Language/design