Skip to content

Fix indexed Set on typed slices - #186

Merged
hanzei merged 2 commits into
stretchr:masterfrom
yousefissa:fix-indexed-set-typed-slices
Oct 15, 2026
Merged

hanzei merged 2 commits into
stretchr:masterfrom
yousefissa:fix-indexed-set-typed-slices

Conversation

@yousefissa

@yousefissa yousefissa commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Closes #185.

Indexed Set on typed slices writes into a temporary []any, losing the update. Assign through the original slice storage instead, including nested and named slices, without copying the final slice.

Preserve []any in-place mutation and use the same behavior for typed slices. Ignore incompatible values without conversion or panic; accept nil only for element types that can hold nil. Update the Set documentation and add regressions for aliasing, assignability, nil values (including typed nil in interfaces), and unsupported paths.

Validation

  • go test -race -count=1 ./... passes on Go 1.25.0 and 1.26.8.
  • golangci-lint v2.14.0 reports zero issues; formatting checks pass.
  • go generate ./... leaves generated files unchanged.

Prepared with OpenAI Codex.

@hanzei hanzei left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hanzei
hanzei merged commit 98bd7e1 into stretchr:master Oct 15, 2026
6 of 8 checks passed
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.

Indexed Set silently does nothing on typed slices like []string

2 participants