slices: Replace does not zero trailing elements if if j == len(s) and i > 0 #65669
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Go version
go version go1.22.0 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Using
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3
, I calledslices.Replace
, to shift elements from the end of the slice, and noticed it didn't clear as documented.For context, I was using Replace like:
But I found that it wasn't behaving per the docs:
Debugging the code shows it hit the second guard in the current implementation:
And I've confirmed it only appears to be an issue for that one edge case, so it's probably just an oversight / easy to fix bug.
What did you see happen?
Elements in the range (specified by
i
andj
) weren't one of: overwritten, zeroed. Specifically, they weren't zeroed.From the runnable example:
What did you expect to see?
The runnable example should have only printed
input: [1 2 3 4 5 6 7 8 9 10]
.The text was updated successfully, but these errors were encountered: