Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
leohhhn opened this issue Jun 27, 2024 · 0 comments · Fixed by #2454
Closed

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

leohhhn opened this issue Jun 27, 2024 · 0 comments · Fixed by #2454
Assignees

Comments

@leohhhn
Copy link
Contributor

leohhhn commented Jun 27, 2024

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

@deelawn deelawn closed this as completed in 3b42391 Jul 2, 2024
gfanton pushed a commit to gfanton/gno that referenced this issue Jul 23, 2024
Closes gnolang#2449.

I believe the bug was introduced by gnolang#2255. Previously, if the type of
`tv.V` in `GetFirstObject` was a `PointerValue`, it the `Base` would
have been nil in the scenario producing this bug. Now that `Base` can
never be nil for a `PointerValue`, the nil base check has been removed.
We do however need to account for a new scenario where the `Base` is a
`RefValue`, a type that does implement the `Object` interface. In the
case where the base is a `RefValue`, first resolve it by calling
`store.GetObject`.

<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
- [x] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

2 participants