Skip to content

Add opt-in uint, nint, and nuint indexers for fixed buffer helper structs#741

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-feature-fixedbuffer-indexers
Jul 13, 2026
Merged

Add opt-in uint, nint, and nuint indexers for fixed buffer helper structs#741
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-feature-fixedbuffer-indexers

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Adds an opt-in generate-fixed-buffer-indexer-overloads config switch (GenerateFixedBufferIndexerOverloads). When set, the compatible-codegen _e__FixedBuffer helper emits uint, nint, and nuint indexer overloads alongside the default ref T this[int index] one, so callers can index without casting. Pointer element access accepts all four index types, so the getter body is identical for each overload.

The switch defaults off, so the emitted int indexer is byte-identical and there is zero golden churn -- default-off correctness is covered by the existing goldens passing unchanged.

The non-compatible Unsafe.Add/AsSpan()[index] path only accepts an int index and is intentionally left as-is (those APIs have no uint/nint/nuint overloads without casts).


The switch is not yet added to the .rsp files, so the self-hosted sources/ClangSharp.Interop bindings are unchanged. Enabling it there and regenerating can be a follow-up.

Fixes #450

…ucts

Add a `generate-fixed-buffer-indexer-overloads` config switch
(`GenerateFixedBufferIndexerOverloads`). When set, the compatible-codegen
`_e__FixedBuffer` helper emits `uint`, `nint`, and `nuint` indexer
overloads alongside the default `ref T this[int index]` one, so callers can
index without casting. Pointer element access accepts all four types, so the
getter body is identical and the int indexer is unchanged when the switch is
off. The non-compatible `Unsafe.Add`/`AsSpan()[index]` path only accepts an
int index and is intentionally left as-is.

Fixes dotnet#450

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding tannergooding merged commit 847e5f9 into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding tannergooding deleted the tannergooding-feature-fixedbuffer-indexers branch July 13, 2026 14:58
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.

Expose additional indexers for generated _e__FixedBuffer types

1 participant