Skip to content

Define what the generators do with a union or a closed class, through IsUnion and IsClosed #223

Open

Description

@CaffeinatedCoder

What you're trying to do

Use a C# 15 union or a closed class next to TypeKit's value objects, in a project woven by Metalama 2027 (C# 15 on net11.0), and get either a working value object or a clear diagnostic. Never one that compiles and does less than it appears to.

Two shapes have no defined answer today, because Metalama 2026.1 can't compile them in a woven project (decision 120):

  1. A value object that wraps a union or a closed type: readonly partial record struct PetId : IValue<Pet>; where Pet is a union. The generated JSON goes through GeneratedJsonPlan<T>, and System.Text.Json has union support (net11.0: Option/Result refusal and value-object JSON under System.Text.Json's union support #213). A union has no IParsable, no IComparable and no type converter of its own.
  2. A union or a closed class that claims a TypeKit contract, for example a union declared with IValue<int> or IClosedSet<TSelf>, if C# 15 lets a union declare interfaces at all.

What you'd like

  • Metalama 2027.0's INamedType.IsUnion, IsClosed and IUnionFacet (release notes, "Unions" and "Closed classes") let the fabric and the aspects tell these shapes apart. That's the code model's answer, not a name.
  • For each shape, decide: generated and tested (the JSON byte for byte as the wrapped union's), or refused with a CMTK diagnostic that names the shape. A new diagnostic ships at Warning, since a minor never adds an Error (decision 34).
  • Rows for unions and closed types join the generated-type axes, on the net11.0 test run.

Needs #173 and the net11.0 target (#208).

Does it change something that compiles or works today?

No. Neither shape compiles in a woven project before 2.4.0, which moves to Metalama 2027.0 (decision 129). That is why this is 2.4.0 work: the release that makes them compile defines what they do.

Activity

  1. added this to the 2.5.0 milestone on Oct 31, 2026
  2. added
    enhancement
    package/generators
    on Oct 31, 2026
  3. added
    area/value-objects
    on Oct 31, 2026
  4. modified the milestones: 2.5.0, 2.4.0 on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/value-objectsenhancementpackage/generators

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions