You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
changed the title [-]slices: Insert function does not panic if i is out of range and there are not values to insert[/-][+]slices: Insert function does not panic if i is out of range and there are no values to insert[/+]on Nov 2, 2023
Interesting edge case. I looked back at the original implementation of slices.Insert when it was just moved into the stdlib, and that one panics for the test cases specified here. However, following the optimizations in https://go-review.googlesource.com/c/go/+/494817 it no longer panics for these cases. @randall77@cuonglm WDYT?
Activity
[-]slices: Insert function does not panic if i is out of range and there are not values to insert[/-][+]slices: Insert function does not panic if i is out of range and there are no values to insert[/+]bcmills commentedon Nov 2, 2023
The documentation does indeed claim that it will panic:
“Insert panics if i is out of range.”
(attn @ianlancetaylor @eliben)
eliben commentedon Nov 2, 2023
Interesting edge case. I looked back at the original implementation of
slices.Insert
when it was just moved into the stdlib, and that one panics for the test cases specified here. However, following the optimizations in https://go-review.googlesource.com/c/go/+/494817 it no longer panics for these cases. @randall77 @cuonglm WDYT?randall77 commentedon Nov 3, 2023
Making it panic in these cases is fine.
gopherbot commentedon Nov 6, 2023
Change https://go.dev/cl/540155 mentions this issue:
slices: make Insert panic if index is out of range and there are no values
gopherbot commentedon Nov 15, 2023
Change https://go.dev/cl/542455 mentions this issue:
slices: imporve Insert panic message for index out of range
slices: improve Insert panic message for index out of range