diff --git a/gnovm/pkg/gnolang/ownership.go b/gnovm/pkg/gnolang/ownership.go index 24d70b5dd84..16aeb905173 100644 --- a/gnovm/pkg/gnolang/ownership.go +++ b/gnovm/pkg/gnolang/ownership.go @@ -333,7 +333,7 @@ func (tv *TypedValue) GetFirstObject(store Store) Object { // something in it; in that case, ignore the base. That will // likely require maybe a preparation step in persistence // ( or unlikely, a second type of ref-counting). - return cv.Base.(Object) + return cv.GetBase(store) case *ArrayValue: return cv case *SliceValue: diff --git a/gnovm/pkg/gnolang/values.go b/gnovm/pkg/gnolang/values.go index d38c083428c..ef367f2c480 100644 --- a/gnovm/pkg/gnolang/values.go +++ b/gnovm/pkg/gnolang/values.go @@ -192,7 +192,6 @@ const ( PointerIndexNative = -3 // Base is *NativeValue. ) -/* func (pv *PointerValue) GetBase(store Store) Object { switch cbase := pv.Base.(type) { case nil: @@ -204,10 +203,9 @@ func (pv *PointerValue) GetBase(store Store) Object { case Object: return cbase default: - panic("should not happen") + panic(fmt.Sprintf("unexpected pointer base type %T", cbase)) } } -*/ // cu: convert untyped; pass false for const definitions // TODO: document as something that enables into-native assignment. diff --git a/gnovm/tests/files/issue-2449.gno b/gnovm/tests/files/issue-2449.gno new file mode 100644 index 00000000000..6af4dbafc6c --- /dev/null +++ b/gnovm/tests/files/issue-2449.gno @@ -0,0 +1,65 @@ +// PKGPATH: gno.land/r/evt_test +package evt_test + +type Event struct { + name string +} + +var deletionEvents = []*Event{ + {name: "event1"}, + {name: "event2"}, + {name: "event3"}, + {name: "event4"}, +} + +var insertEvents = []*Event{ + {name: "event1"}, + {name: "event2"}, +} + +var appendEvents = []*Event{ + {name: "event1"}, +} + +func DelEvent(name string) { + for i, event := range deletionEvents { + if event.name == name { + deletionEvents = append(deletionEvents[:i], deletionEvents[i+1:]...) + return + } + } +} + +func InsertEvent(name string) { + insertEvents = append(insertEvents[:1], append([]*Event{{name: name}}, insertEvents[1:]...)...) +} + +func AppendEvent(name string) { + appendEvents = append(appendEvents, &Event{name: name}) +} + +func printEvents(events []*Event) { + for _, event := range events { + println(event.name) + } +} + +func main() { + DelEvent("event2") + InsertEvent("event1.5") + AppendEvent("event2") + + printEvents(deletionEvents) + printEvents(insertEvents) + printEvents(appendEvents) +} + +// Output: +// event1 +// event3 +// event4 +// event1 +// event1.5 +// event2 +// event1 +// event2