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

can't use unexported struct fields when converting using gno2go #1155

Open
thehowl opened this issue Sep 19, 2023 · 0 comments
Open

can't use unexported struct fields when converting using gno2go #1155

thehowl opened this issue Sep 19, 2023 · 0 comments
Assignees

Comments

@thehowl
Copy link
Member

thehowl commented Sep 19, 2023

This happens mostly when doing a "gonative" call, such as is the case for (testing.T).Log, or more generally fmt.Sprintf.

package main

import "fmt"

type X struct {
        v string
}

func main() {
        fmt.Printf("test %#v", X{v: "a"})
}
$ gno run a.gno
panic running expression main(): reflect: reflect.Value.SetString using value obtained using unexported field

My opinion is that in the long run we should aim to drop all the gonative opcodes and code; it appears to me that gonative is mostly especially useful for "bootstrapping" functions in Gno, and is currently still useful mostly for functions like fmt.Sprintf, which would need to rely on reflection to work as expected.

However, to support use cases (such as mine, where I was trying to simply t.Log a struct) we may add a temporary fix to the problem.

On the patch/gnochess branch, I changed this line to make the struct field exported. This is a dirty trick, but it does the job:

$ gno run a.gno
test struct { Xv string }{Xv:"a"}%

Should a fix like this one be added to the main branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🚀 Needed for Launch
Development

No branches or pull requests

3 participants