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

[bug/gnovm] arrays returned by functions should not be addressable #2299

Open
deelawn opened this issue Jun 6, 2024 · 3 comments · May be fixed by #2731 or #3198
Open

[bug/gnovm] arrays returned by functions should not be addressable #2299

deelawn opened this issue Jun 6, 2024 · 3 comments · May be fixed by #2731 or #3198
Assignees
Labels
🐞 bug Something isn't working in focus Core team is prioritizing this work 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@deelawn
Copy link
Contributor

deelawn commented Jun 6, 2024

This bug highlights a difference between gno and go. Here is an example

package main

import "crypto/sha256"

func main() {
	println(sha256.Sum256([]byte("x"))[:])
}

This will execute fine as gno code, but running it as go code yields
invalid operation: sha256.Sum256([]byte("x")) (value of type [32]byte) (slice of unaddressable value)

https://goplay.tools/snippet/MxwoBhtYZzz

@petar-dambovaliev
Copy link
Contributor

I think, this might be a clearer example of the problem.

package main

func main() {
	foo()[:] // ./prog.go:4:2: invalid operation: foo() (value of type [2]byte) (slice of unaddressable value)
}

func foo() [2]byte {
	return [2]byte{1, 2}
}

@petar-dambovaliev
Copy link
Contributor

petar-dambovaliev commented Jul 30, 2024

This also works, when it shouldn't.

func main() {
	arr := &getArray()[0]
	println(arr)
}

func getArray() [3]int {
	return [3]int{1, 2, 3}
}

and this

type Point struct {
	X, Y int
}

func main() {
	arr := &[3]Point{{1, 2}, {3, 4}, {5, 6}}[0]
	println(arr)
}

@Kouteki
Copy link
Contributor

Kouteki commented Oct 21, 2024

Should mostly be fixed by Dylan. We can continue Dylan's work. Maxwell will take it up.

@Kouteki Kouteki moved this from Backlog to Todo in 🧙‍♂️gno.land core team Oct 28, 2024
@ltzmaxwell ltzmaxwell added the in focus Core team is prioritizing this work label Nov 15, 2024
@Kouteki Kouteki linked a pull request Nov 28, 2024 that will close this issue
@Kouteki Kouteki moved this from Todo to In Progress in 🧙‍♂️gno.land core team Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working in focus Core team is prioritizing this work 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: In Progress
5 participants