Skip to content

Keep conditional guards on split type forwards - #725

Merged
SimonCropp merged 1 commit into
mainfrom
keep-type-forward-guards
Nov 19, 2026
Merged

SimonCropp merged 1 commit into
mainfrom
keep-type-forward-guards

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

Problem

The first build on the .NET 11 GA SDK fails on ConsumeBclMemory for net9.0:

Split\net9.0\TypeForwardeds.cs(5,55): error CS0433: The type 'Base64Url' exists in both
'Microsoft.Bcl.Memory, Version=11.0.0.0' and 'System.Runtime, Version=9.0.0.0'

Microsoft.Bcl.Memory 11.0.0 dropped its net8.0 and net9.0 builds (10.0.14 had both). A net9.0 project now gets the package's netstandard2.1 build, which defines its own Base64Url, and that clashes with the one built into .NET 9.

src/Polyfill/Base64Url.cs already handles this: the whole file, including the forward, is behind #if FeatureMemory && !RefsBclMemory. But when the splitter moves TypeForwardedTo lines into the combined TypeForwardeds.cs, it copies just the line and drops the #if blocks around it. So Split/net9.0/TypeForwardeds.cs forwarded Base64Url unconditionally.

This affects consumers as well as CI. The shipped Split files have the same unguarded line, so any net9.0 project that references Microsoft.Bcl.Memory 11.0.0, directly or through another package, fails to compile even if it never uses Base64Url.

Fix

  • Splitter.ExtractTypeForwards walks the processed lines with a directive stack. Each forward it lifts out records the guard formed by the #if blocks around it. A forward in an #elif or #else branch also gets the earlier branch conditions, negated.
  • Splitter.BuildTypeForwardedsLines lists unguarded forwards first, then one #if … #endif block per guard.
  • Regenerated the 12 affected src/Split/*/TypeForwardeds.cs files. Each framework has exactly the same set of forwards as before; only the guards and order changed. 15 other forwards had also lost a FeatureMemory, FeatureValueTuple && !RefsBclMemory (Index/Range) or similar guard; they have them back.

Verification

  • New SplitterTests cover:
    • the Base64Url case
    • a forward with no guard
    • #elif/#else negation and nested blocks
    • the grouped output
    • a check that the generated net9.0 file keeps the Microsoft.Bcl.Memory guard on Base64Url
  • ApiBuilderTests (Debug): 92/92 pass.
  • ConsumeBclMemory builds for every framework against Microsoft.Bcl.Memory 11.0.0. With the old net9.0 file restored, it fails with the same CS0433.
  • dotnet build src/Polyfill.slnx --configuration Release: 0 errors, 0 warnings.
  • run-tests.ps1 not run locally.

The splitter moved TypeForwardedTo lines into TypeForwardeds.cs without the preserved #if blocks around them, so the Base64Url forward lost its !RefsBclMemory guard. Microsoft.Bcl.Memory 11.0.0 has no net9.0 build, so on net9.0 its netstandard2.1 Base64Url clashed with the in-box type (CS0433).

Forwards now keep the guards they had in the source, grouped by guard in TypeForwardeds.cs.
@SimonCropp SimonCropp added this to the 11.5.0 milestone Nov 19, 2026
@SimonCropp
SimonCropp merged commit 5f9a682 into main Nov 19, 2026
4 checks passed
@SimonCropp
SimonCropp deleted the keep-type-forward-guards branch November 19, 2026 04:40
This was referenced Nov 23, 2026
This was referenced Nov 23, 2026
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.

1 participant