On Fri, Jan 24, 2025 at 11:57:14PM -0800, Pyrode wrote:
> The following code <
https://go.dev/play/p/P2gPMHKuJW8> allows elements
> outside the length of the slice to be accessed.
> Is this the expected behaviour or a bug?
This is expected.
They still share the same underlying data array after all.
https://go.dev/blog/slices-intro might be insightful for you.
If you want to prevent that, return a copy or truncate the cap.
slices.Clip / slices.Clone are helpful there, depending on what
constraints you need.