Closed leohhhn closed 7 months ago
Assuming the behavior in the Gno is identical to that of the Go language for convenience.
In Go, slices are fundamentally reference types. When using posts := m.Posts
, both posts
and m.Posts
point to the same data. But they operate as separate references (i.e., independent slices). This means that while metadata (length or capacity) of the slice is copied, the content of the data array they internally point to is shared.
Therefore, deleting an element from the posts slice does not affect the m.Posts
slice because although both slices access the same data array, each slice has different metadata. Due to these characteristics, changes made to posts are not reflected in m.Posts
IMHO.
Here's my reproduction code:
I think we can close this as intended behavior. @notJoon is mostly correct -- but many cases modifying a single slice element will affect other slices that reference the same underlying array, and this is intended to mirror the go functionality. Slices will continue to use the same underlying array until the array needs to grown / reallocated.
Here is an example: https://play.gno.land/p/zSEYhS76ym3
@leohhhn please close if you agree.
Looking into this in more detail, it is actually intended behavior. Closing this. Thanks @notJoon @deelawn
Description
I believe I found an issue in the GnoVM, while writing the Memeland realm. With the following code:
When making a pointer copy of
m.Posts
, and updating that value, them.Posts
slice does not get updated.