-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 "required members" #57046
Comments
Implements parsing for required members. Test plan: dotnet#57046 Spec: dotnet/csharplang#3630
Adding `required` to a member now results in the type having a `RequiredMembersAttribute` emitted with the name of that member as the contents. Reading this data from metadata is not yet supported, nor is adding the requisite `ObsoleteAttribute` to constructors that depend on such contracts. The rules for when required is allowed and when it is disallowed are documented in dotnet/csharplang#5566, pending LDM review. Test plan: dotnet#57046
Implements parsing for required members. Test plan: #57046 Spec: dotnet/csharplang#3630
Adding `required` to a member now results in the type having a `RequiredMembersAttribute` emitted with the name of that member as the contents. Reading this data from metadata is not yet supported, nor is adding the requisite `ObsoleteAttribute` to constructors that depend on such contracts. The rules for when required is allowed and when it is disallowed are documented in dotnet/csharplang#5566, pending LDM review. Test plan: dotnet#57046
Adding `required` to a member now results in the type having a `RequiredMemberAttribute` emitted on the member and the containing type. Reading this data from metadata is not yet supported, nor is adding the requisite `ObsoleteAttribute` to constructors that depend on such contracts. The rules for when required is allowed and when it is disallowed are documented in dotnet/csharplang#5566. Test plan: #57046
Implements reading the required members list of a type, and enforces that required members are all set by an initializer on the constructor. Required members must be initialized with values, not with nested object initializers. Test plan dotnet#57046. Specification https://github.com/dotnet/csharplang/blob/main/proposals/required-members.md
Implements reading the required members list of a type, and enforces that required members are all set by an initializer on the constructor. Required members must be initialized with values, not with nested object initializers. Test plan #57046. Specification https://github.com/dotnet/csharplang/blob/main/proposals/required-members.md
The SetsRequiredMembersAttribute prevents the compiler from checking the required member list of a type when calling that constructor, and suppresses any errors from a base type's list being invalid. Specification: https://github.com/dotnet/csharplang/blob/main/proposals/required-members.md Test plan: dotnet#57046
The SetsRequiredMembersAttribute prevents the compiler from checking the required member list of a type when calling that constructor, and suppresses any errors from a base type's list being invalid. Specification: https://github.com/dotnet/csharplang/blob/main/proposals/required-members.md Test plan: dotnet#57046
The SetsRequiredMembersAttribute prevents the compiler from checking the required member list of a type when calling that constructor, and suppresses any errors from a base type's list being invalid. Specification: https://github.com/dotnet/csharplang/blob/main/proposals/required-members.md Test plan: #57046
Adds support for decoding and reporting errors when `CompilerFeatureRequiredAttribute` is encountered on metadata type symbols. We also block applying the attribute by hand in both C# and VB. Test plan: dotnet#57046
Adds support for decoding and reporting errors when `CompilerFeatureRequiredAttribute` is encountered on metadata type symbols. We also block applying the attribute by hand in both C# and VB. Test plan: dotnet#57046
Any updates for |
I'm not sure what you're asking about. This issue is tracking adding tests. |
This comment was marked as outdated.
This comment was marked as outdated.
See https://sharplab.io/#v2:EYLgtghglgdgPgAQEwEYCwAoTAnApgYwHtsATAAgDFDCAKPARwFco9zYAXMgDQEoBuIA We still cannot use |
For new additions to the feature, please use csharplang. However, for this particular request, I'll save you some time by telling you that you don't really want it. If you mark a property as required, it must be set with a property initializer. No ifs, ands, or buts. This would create a primary constructor that takes a parameter to set the property, and you must then use an object initializer to set the property again. |
@jasonmalinowski I think we're ready to close this test plan from the compiler side. The follow-up compiler work is tracked by separate issues. |
@333fred will follow-up with runtime team on possibility of Reflection API and file an issue if there's interest. |
Championed proposal: dotnet/csharplang#3630
Specification: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-11.0/required-members.md
Compiler
RequiredMembers
attribute in compiler layer/API (issue Consider filteringRequiredMembers
attribute in compiler layer/API #61511)declaration
required
as contextual keyword ("required" type, type parameter, etc exists in scope)required
modifier is allowed/disallowedrequired
modifier based on LangVerrequired
type name based on LangVerRequiredMember
attribute disallowed in sourcerequired
with field/property initializer (allowed)SetsRequired
SetsRequired
whenSetsRequired
onbase
orthis
fixed
,ref readonly
,ref
,const
,static
disallowed; others such asextern
,partial
,virtual
allowed)metadata
Required
attribute cannot be manually appliedrequired
members are markedRequired
and the type too. But not if merely derived from a type with required members.CompilerFeatureRequired
with marker stringObsolete
with marker stringSetsRequired
set on record copy ctorusage
new C { Inner = new D { ... } }
versusnew C { Inner = { ... } }
new()
constraint not satisfiednullability
[SetsRequiredMembers]
with required membersLDM
required
property with an initializer (useless)? (answer: no, can be useful)readonly
modifier? (disallow)BCL
required
?Productivity:
required
) (no change, manually verified)The text was updated successfully, but these errors were encountered: