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

println does not print nil slices #1377

Closed
thehowl opened this issue Nov 16, 2023 · 5 comments
Closed

println does not print nil slices #1377

thehowl opened this issue Nov 16, 2023 · 5 comments
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@thehowl
Copy link
Member

thehowl commented Nov 16, 2023

package main

func main() {
        var a []string
        println(a)
}

panics with:

panic: interface conversion: gnolang.Value is nil, not *gnolang.SliceValue [recovered]
        panic: interface conversion: gnolang.Value is nil, not *gnolang.SliceValue

goroutine 1 [running]:
main.runExpr.func1()
        /home/howl/oc/gno2/gnovm/cmd/gno/run.go:158 +0x125
panic({0xc0ae00?, 0xc00047c840?})
        /usr/lib/go/src/runtime/panic.go:914 +0x21f
github.com/gnolang/gno/gnovm/pkg/gnolang.(*TypedValue).Sprint(0xc0001218c8, 0xc00047c780?)
        /home/howl/oc/gno2/gnovm/pkg/gnolang/values_string.go:230 +0xe71
github.com/gnolang/gno/gnovm/pkg/gnolang.UverseNode.func11(0xc000177200)
        /home/howl/oc/gno2/gnovm/pkg/gnolang/uverse.go:947 +0x1ee
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).doOpCallNativeBody(...)
        /home/howl/oc/gno2/gnovm/pkg/gnolang/op_call.go:166
@thehowl thehowl added 🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related labels Nov 16, 2023
@thehowl thehowl added this to the 🚀 main.gno.land (required) milestone Nov 16, 2023
@thehowl thehowl moved this to 🚀 Needed for Launch in 🚀 The Launch [DEPRECATED] Nov 16, 2023
@notJoon
Copy link
Member

notJoon commented Nov 16, 2023

The section in gnolang where println is called is from lines 935 to 955 in uverse.go. It seems to be an issue caused by not handling nil values in this part. However, when the same code is run in Go, it outputs [0/0]0x0. Should we modify it to simply print undefined instead?

@thehowl
Copy link
Member Author

thehowl commented Nov 16, 2023

Should we modify it to simply print undefined instead?

Yeah, sounds adequate.

@ajnavarro
Copy link
Contributor

ajnavarro commented Nov 20, 2023

@thehowl do we want to modify standard Go behavior on Gno changing [0/0]0x0 output to undefined?

IMHO we should default to keep the same behavior unless there is a good reasoning behind the change. We cannot know the implications of most of the changes until we hit the problem eventually.

@thehowl
Copy link
Member Author

thehowl commented Nov 20, 2023

@ajnavarro println and print are not properly "standardized" function where we should strive to have 100% compatibility with Go. See: Go spec#Bootstrapping, builtin#println. The documentation explicitly says:

The println built-in function formats its arguments in an implementation-specific way

(emphasis mine)

I think printing undefined is acceptable as it is consistent with the behaviour when you perform println(nil).

moul pushed a commit that referenced this issue Dec 5, 2023
The `println` function was encountering issues when trying to process
nil values(e.g. nil slice). This was causing memory errors. The issue
has been addressed by adding checks for nil values and handling them
appropriately to prevent memory errors.

related with: #1377
@thehowl
Copy link
Member Author

thehowl commented Dec 7, 2023

Fixed by #1380

(@notJoon use "linking keywords" for your next PRs; see github doc)

@thehowl thehowl closed this as completed Dec 7, 2023
gfanton pushed a commit to moul/gno that referenced this issue Jan 18, 2024
The `println` function was encountering issues when trying to process
nil values(e.g. nil slice). This was causing memory errors. The issue
has been addressed by adding checks for nil values and handling them
appropriately to prevent memory errors.

related with: gnolang#1377
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: 🚀 Needed for Launch
Development

No branches or pull requests

3 participants