Repository navigation
Support C# union types - #476
pixsperdavid wants to merge 3 commits into
Conversation
[MemoryPackable] partial union declarations serialize Value as a union header plus the case value. Tags default to the case's declaration position and can be set with [MemoryPackUnion(tag, typeof(Case))].
Union diagnostics renumbered to MEMPACK044/045 as MEMPACK043 is now used upstream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Only Cysharp organization members and Dependabot are permitted to change |
|
The change to .github is necessary to allow the unit tests to function. |
|
@neuecc Could I request that this automated decision be reviewed? |
|
I checked it and it looks fine, so I reopened it. |
|
@pixsperdavid Could you remove the changes under Our policy bot reacts to any Workflow changes have to be made by Cysharp members, so the .NET 11 SDK setup for CI will be handled separately on our side. |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I've reverted the workflow changes, everything will still compile however the new functionality will be untested until the tests are compiled and run with .NET 11. |
Adds support for C# 15 union declarations:
Value is written as a union header followed by the case value, using the existing union header encoding. An empty union (Value is null) is written as null, and reads back as default.
Tags: by default, a case’s tag is its zero-based position in the declaration, so new cases must be added at the end. Tags can also be set explicitly with [MemoryPackUnion(tag, typeof(Case))]. When any are given, every case needs exactly one (MEMPACK044). To allow this, MemoryPackUnionAttribute can now be applied to structs. Using it on a [MemoryPackable] struct that isn’t a union is an error (MEMPACK045).
Notes:
Layout options: GenerateType and SerializeLayout options have no effect on unions.
Overlapping cases: the first matching case in declaration order is used.
Generic case types: cases like T can’t be tagged explicitly, because C# doesn’t allow typeof(T) in an attribute.
Union tests: the tests target net11.0, but only when the .NET 11 SDK is used to build them. CI will now install 11.0.x.
Diagnostic tests: errors that need union syntax have no generator diagnostic tests yet. The test harness uses Roslyn 4.4.0, which can’t parse it.