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. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/4uhrdnkzbbk4ucq2e4ld7g4unjvmqjoaj5yfq3cmchugucg3y5%40o5zxbcm63wrm.