Add opt-in uint, nint, and nuint indexers for fixed buffer helper structs#741
Merged
tannergooding merged 1 commit intoJul 13, 2026
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an opt-in
generate-fixed-buffer-indexer-overloadsconfig switch (GenerateFixedBufferIndexerOverloads). When set, the compatible-codegen_e__FixedBufferhelper emitsuint,nint, andnuintindexer overloads alongside the defaultref 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
intindexer 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 anintindex and is intentionally left as-is (those APIs have nouint/nint/nuintoverloads without casts).The switch is not yet added to the
.rspfiles, so the self-hostedsources/ClangSharp.Interopbindings are unchanged. Enabling it there and regenerating can be a follow-up.Fixes #450