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
Okay, I did deeper investigations and what to expect. But although it is not intuitive, it is technically correct behaviour.
The weird thing is, that different pointers to the same slice have the same (c and d) or different (b and c/d) contents; b, c and d are different pointers, but c and d point literally to the same content while b does not.
Go version
go version 1.19.1, 1.20, 1.21 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I reproduced the issue on https://go.dev/play/p/gRUHj2w1DmJ:
a
->a
has expected valueb
usingappend
to add an item toa
->b
has expected valuec
usingappend
to add an item tob
->c
has expected valued
usingappend
to add an other item tob
d
has expected valuec
has the value ofd
I tried also with global
var
s and:=
variable declarations. The result always was the same, so I suggest this is a problem in the behaviour ofappend
.What did you see happen?
In my example, I added the output of the pointers, which are correct.
So the last call to
append
is changing the contents ofc
, although onlyd
is being touched.What did you expect to see?
I expect to see the value of
c
remain untouched when creatingd
by appending an item tob
, asc
is not interacting in any way.The text was updated successfully, but these errors were encountered: