gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
841 stars 342 forks source link

[GnoVM] Missing method DecRefCount when deleting element in pointer slice #2449

Open leohhhn opened 4 days ago

leohhhn commented 4 days ago

Description

GnoVM errors with Data: interface conversion: gnolang.RefValue is not gnolang.Object: missing method DecRefCount when trying to remove an element from a slice of pointers to structs. Check out the txtar below to reproduce.

Below test fails at calling DelEvent:

loadpkg gno.land/r/demo/evt $WORK

# start a new node
gnoland start

gnokey maketx call -pkgpath gno.land/r/demo/evt -func AddEvent -args "MyEvent1" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
gnokey maketx call -pkgpath gno.land/r/demo/evt -func AddEvent -args "MyEvent2" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

gnokey maketx call -pkgpath gno.land/r/demo/evt -func DelEvent -args "MyEvent1" -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

-- evt.gno --
package evt

type Event struct {
    name        string
}

type eventSlice []*Event

var events eventSlice

func init() {
    events = make(eventSlice, 0)
}

func AddEvent(name string) {
    events = append(events, &Event{name: name})
}

func DelEvent(name string) {
    for i, event := range events {
        if event.name == name {
            events = append(events[:i], events[i+1:]...)
            return
        }
    }
}

Found while working on #2372