Skip to content

Evaluate a shipped Roslyn analyzer that reports a type derived from a range union at compile time #210

Open

Description

@CaffeinatedCoder

Idea

#206 seals the range unions at runtime: the explicit copy constructor throws for any runtime type that is not nested in the union. A consumer who writes record Rogue(Int32Range Seed) : Int32Range(Seed); still compiles and only learns at the first construction. A Roslyn analyzer packed into the core and NodaTime packages (analyzers/dotnet/cs) could report the derivation at the declaration site, with the union's name and the reason.

What it is and is not

  • It is a developer-experience layer only. An analyzer runs only in a compiler that loads it, a consumer can switch it off (#pragma warning disable, NoWarn, .editorconfig), and Reflection.Emit never sees it, so the runtime seal from Range unions are not closed: the synthesized protected copy constructor admits a sixth variant #206 stays the guarantee and the analyzer must never replace it.
  • It is a fifth shipping artefact: a netstandard2.0 project on Microsoft.CodeAnalysis.CSharp, tests on Microsoft.CodeAnalysis.Testing, packaging wiring in both nuspecs, a consumer in test/consumer-smoke-test.sh that asserts the diagnostic, and the carrying cost the 2026-10-18 external assessment warned about.

Decide after #148

#148 probes C# 15 closed hierarchies on net10.0 and net11.0. If closed records ship and apply to the unions, the compiler reports the derivation itself and this analyzer has nothing left to do. If they do not reach net10.0, this is the compile-time half for the 10.x line.

Done looks like: a decision recorded here (ship, or close as superseded by #148), and if ship, a sub-issue under the release epic it goes into.

Activity

  1. added
    enhancement
    area/ranges
    package/nodatime
    package/core
    on Oct 18, 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/rangesenhancementpackage/corepackage/nodatime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions