Add IsClosedTypeAttribute#128599
Open
Copilot wants to merge 3 commits into
Open
Conversation
Co-authored-by: tannergooding <10487869+tannergooding@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add ClosedAttribute to support closed class hierarchies
Add IsClosedTypeAttribute
May 26, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new compiler-reserved attribute, System.Runtime.CompilerServices.IsClosedTypeAttribute, to the BCL surface area so the C# compiler can emit it for closed class hierarchies, with corresponding reference assembly and a basic construction test.
Changes:
- Added
IsClosedTypeAttributeimplementation in System.Private.CoreLib with[EditorBrowsable(Never)]and class-onlyAttributeUsage. - Updated the System.Runtime ref assembly to expose the new attribute publicly.
- Added a small xUnit smoke test to ensure the attribute is constructible.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/AttributesTests.cs | Adds a constructor smoke test for IsClosedTypeAttribute. |
| src/libraries/System.Runtime/ref/System.Runtime.cs | Adds the public reference declaration for IsClosedTypeAttribute. |
| src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/IsClosedTypeAttribute.cs | Implements the new compiler-reserved attribute in CoreLib. |
| src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems | Includes the new source file in the CoreLib shared build items. |
RikkiGibson
approved these changes
May 26, 2026
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-runtime |
Co-authored-by: tannergooding <10487869+tannergooding@users.noreply.github.com>
RikkiGibson
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exposes the attribute approved in #128161 (comment), emitted by the C# compiler to mark types declared as
closed(see the closed-hierarchies proposal). Per @bartonjs's feedback, the name was changed fromClosedAttributetoIsClosedTypeAttributesince it is not intended to be written by users.Changes:
src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/IsClosedTypeAttribute.cs, marked[EditorBrowsable(Never)]to match the convention for compiler-only attributes (e.g.RequiresLocationAttribute).System.Private.CoreLib.Shared.projitems.src/libraries/System.Runtime/ref/System.Runtime.cs.AttributesTests.csnext to the existingRequiresLocationAttributetest.AllowMultiple = falsefromAttributeUsagein both implementation and ref declaration to resolve ApiCompat CP0015 (System.Private.CoreLibref/lib attribute argument mismatch).AttributeTargetsis intentionally restricted toClassonly; broadening to interfaces/enums is deferred until those "closed" forms are designed.