Repository navigation
Add RequireNamedArgumentsAttribute - #138159
semirhamid wants to merge 5 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
|
@dotnet-policy-service agree |
There was a problem hiding this comment.
🔵 Needs a closer look
Unavailable label-event history prevents verifying who applied api-approved and when, leaving the repository’s required API-approval check incomplete.
No open issues 🎉
What changed in this PR
Adds System.Diagnostics.CodeAnalysis.RequireNamedArgumentsAttribute to shared CoreLib and the System.Runtime public contract, contributing to #132924. This PR provides the attribute metadata; analyzer enforcement is deferred to separate work.
Changes:
- Defines the sealed attribute, its supported targets, and XML documentation.
- Includes it in shared CoreLib builds and the
System.Runtimereference assembly. - Adds tests for construction, allowed targets, multiplicity, and inheritance settings.
| File | Description |
|---|---|
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Diagnostics/CodeAnalysis/RequireNamedArgumentsAttributeTests.cs | Tests construction and attribute usage metadata. |
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System.Runtime.Tests.csproj | Includes the new tests in the test project. |
| src/libraries/System.Runtime/ref/System.Runtime.cs | Adds the public reference declaration. |
| src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequireNamedArgumentsAttribute.cs | Implements and documents the attribute. |
| src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems | Includes the implementation in shared CoreLib builds. |
Review effort: Balanced
T-Gro
left a comment
There was a problem hiding this comment.
Was this tested with the compiler please? If so, how?
(I don't insist for the test to land in the repo as well, but would be nice to see it in action at least as a PR comment)
Yes, I tested it with both the F# and C# compilers. I built this branch locally and compiled a few small sample projects against the reference assemblies from that build, using the SDK in the repo's .dotnet folder (12.0.100-alpha.1.26557.102, F# 11.2 by default) and the samples don't define the attribute themselves, so it's the one from System.Runtime. and on the F# side calling an attributed method or constructor with positional arguments gives FS3923 and the same calls with named arguments compile fine. I also compiled the same code against the SDK's own reference pack, and there it fails because the attribute doesn't exist. On the other hand for the C# side, the attribute can be applied to a method, constructor, property, indexer, delegate and parameter, and putting it on a class gives CS0592. I only compiled the samples, I didn't run them. The project files and the full compiler output are here if you want to look or rerun it: |
|
/ba-g Known test errors, unrelated DeadLetter, and unrelated networking timeout |
Adds
System.Diagnostics.CodeAnalysis.RequireNamedArgumentsAttribute, matching the API shape approved in the API review comment on the issue.SetsRequiredMembersAttribute.AttributeUsagetargets,AllowMultipleandInherited.This PR covers the attribute only. The C# analyzer is out of scope and will follow separately.
Validation (macOS arm64, Xcode 27.3 beta)
./build.sh -subset clr+libs -rc Release: succeeded, 0 warnings, 0 errors../build.sh clr.corelib+clr.nativecorelib+libs.pretest -rc Release: succeeded.RequireNamedArgumentsAttributeTests: 2 run, 2 passed. The rest of the System.Runtime tests were not run locally.Contributes to #132924