Skip to content

Support closed and union syntax via preview Roslyn#1881

Draft
wuzzeb wants to merge 1 commit into
belav:mainfrom
wuzzeb:closed-and-union
Draft

Support closed and union syntax via preview Roslyn#1881
wuzzeb wants to merge 1 commit into
belav:mainfrom
wuzzeb:closed-and-union

Conversation

@wuzzeb

@wuzzeb wuzzeb commented Jul 3, 2026

Copy link
Copy Markdown

Description

Add closed to modifier ordering and route Roslyn's preview UnionDeclaration syntax kind through the existing base type declaration printer. Add formatting coverage for closed record classes and union declarations.

For modifier ordering, the current IDE0036 default-order documentation does not yet list the new closed modifier, so this PR makes a local ordering choice rather than copying an official one. I placed closed with the inheritance/type-shape modifiers, directly after abstract and before sealed, because the C# preview docs describe closed as a class modifier for closed hierarchies, and it is related to inheritance constraints. That keeps it near the modifiers it semantically overlaps with while leaving the existing documented order otherwise unchanged.

Microsoft.CodeAnalysis.CSharp

Unfortunately, the published nuget for Microsoft.CodeAnalysis.CSharp does not yet support either closed or union. To implement it temporarily, I reference the packages from the .NET 11 preview 5 SDK. Thus, we should not merge this PR as-is. The idea is to just have something ready.

When Microsoft.CodeAnalysis.CSharp is updated on nuget, we can take out the RoslynPreviewSdkReferences.props file and all the overrides and just use the nuget package, and then the PR will be ready to merge.

This draft intentionally references the .NET 11 Preview 5 SDK Roslyn assemblies for net10.0 builds because matching Microsoft.CodeAnalysis.CSharp NuGet packages are not yet published. Replace RoslynPreviewSdkReferences.props with a normal NuGet package update before merging.

Related Issue

Fixes #1880

Checklist

  • My code follows the project's code style
    • always var
    • follow existing naming conventions
    • always this.
    • no pointless comments
  • I will not force push after a code review of my PR has started
  • I have added tests that cover my changes

Add closed to modifier ordering and route Roslyn's preview UnionDeclaration syntax kind through the existing base type declaration printer. Add formatting coverage for closed record classes and union declarations.

This draft intentionally references the .NET 11 Preview 5 SDK Roslyn assemblies for net10.0 builds because matching Microsoft.CodeAnalysis.CSharp NuGet packages are not yet published. Replace RoslynPreviewSdkReferences.props with a normal NuGet package update before merging.
@wuzzeb

wuzzeb commented Jul 3, 2026

Copy link
Copy Markdown
Author

Also, SyntaxKind.UnionDeclaration does not yet exist in the preview 5 version, so had to temporarily use the cast string.... but the parsing and formatting does work (see the test)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support closed modifier

1 participant