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

Unable to call modifying methods on types imported from other realms #1671

Open
deelawn opened this issue Feb 20, 2024 · 2 comments
Open

Unable to call modifying methods on types imported from other realms #1671

deelawn opened this issue Feb 20, 2024 · 2 comments
Assignees
Labels
🐞 bug Something isn't working

Comments

@deelawn
Copy link
Contributor

deelawn commented Feb 20, 2024

I'm not sure this is a problem but it could use further explanation. I was looking at an issue @leohhhn brought up regarding an error he was getting when trying to add a post to a blog. In summary, the issue was:

  • A realm exists with an instance of the Blog type, defined in the blog package
  • Calling a modifying method on the Blog instance results in the error cannot modify external-realm or non-realm object

I wrote a txtar script to exemplify the issue:

gnoland start

gnokey maketx addpkg -pkgdir $WORK/blogtest -pkgpath gno.land/r/blogtest -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
gnokey maketx addpkg -pkgdir $WORK/owner -pkgpath gno.land/r/owner -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

gnokey maketx call -pkgpath gno.land/r/owner -func AddPost -args 'my first post' -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1


-- owner/blog.gno --
package owner

import blog "gno.land/r/blogtest"

var Blog = new(blog.Blog)

func AddPost(title string) {
	Blog.AddPost(title)
}

func GetPost() blog.Post {
	return Blog.Post
}

-- blogtest/blog.gno --
package blogtest

type Blog struct {
	Post  Post
}

type Post struct {
	Title string
}

func (b *Blog) AddPost(title string) {
	b.Post = Post{title}
}

In the case above the error will happen when calling AddPost from the owner realm. I'm not sure why this isn't allowed because the only object being modified is that which is owned by the owner realm, so it isn't as if this call is modifying another realm's state.

@deelawn
Copy link
Contributor Author

deelawn commented Feb 21, 2024

This may be addressed by #1257. Will check to confirm

@moul
Copy link
Member

moul commented Oct 15, 2024

will be addressed by #2743
see also #1257
see also #2526

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
Development

No branches or pull requests

5 participants