Skip to content

Preserve slices when setting an indexed value - #170

Merged
hanzei merged 1 commit into
stretchr:masterfrom
vitalivo:fix/indexed-slice-access
Sep 21, 2026
Merged

hanzei merged 1 commit into
stretchr:masterfrom
vitalivo:fix/indexed-slice-access

Conversation

@vitalivo

Copy link
Copy Markdown
Contributor

Summary

Set("names[0]", "Mat") replaces the entire names slice with "Mat". The existing test misses the data loss because Get("names[0]") also ignores an index on a non-slice and returns that scalar.

For indexed writes into []interface{}, traverse the indices and update the final element instead of assigning the map key. Return a missing value when a read attempts to index a non-slice. Regression tests check that other elements survive, nested writes work, nil can be assigned, and out-of-range writes preserve the slice. Both new tests fail before the fix.

Checklist

  • Tests pass: ran the Taskfile's go test -race ./... with coverage enabled (99.1%).
  • Code style is correct: ran the Taskfile's gofmt -d -s *.go and go vet ./... commands; both are clean.

Validated with Go 1.27.1.

@vitalivo vitalivo closed this Sep 12, 2026
@vitalivo vitalivo reopened this Sep 12, 2026
@hanzei
hanzei self-requested a review September 13, 2026 22:03
@hanzei
hanzei merged commit 89f7fb1 into stretchr:master Sep 21, 2026
6 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.

2 participants