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

cannot convert slice to array #3501

Open
Villaquiranm opened this issue Jan 13, 2025 · 1 comment
Open

cannot convert slice to array #3501

Villaquiranm opened this issue Jan 13, 2025 · 1 comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related 🌱 feature New update to Gno

Comments

@Villaquiranm
Copy link
Contributor

Villaquiranm commented Jan 13, 2025

Slice-to-Array Casting Limitation

Description

In golang you're able to do (https://go.dev/play/p/1gERcS_9z_l)

package main

import "fmt"

func main() {
	var byteArray []byte = []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
	arrayTwenty := [20]byte(byteArray)
	fmt.Println(arrayTwenty)
}

trying to do something equivalent on Gnolang,
you can go to gnovm/stdlibs/std/crypto.go and modify convertTo20Byte function as follows:

func convertTo20Byte(in []byte) [20]byte {
	return [20]byte(in)
}

running
gno test . on sdt package will result on

.: test pkg: panic: cannot convert []uint8 to ArrayKind
go stacktrace:

Your environment

  • Go version (example: go1.22.4)
  • OS and CPU architecture (example: linux/amd64)
  • Gno commit hash causing the issue (example: f24690e)

Steps to reproduce

  • Tell us how to reproduce this issue
  • Where the issue is, if you know
  • Which commands triggered the issue, if any

Expected behaviour

Tell us what should happen

Actual behaviour

Tell us what happens instead

Logs

Please paste any logs here that demonstrate the issue, if they exist

Proposed solution

If you have an idea of how to fix this issue, please write it down here, so we can begin discussing it

@thehowl
Copy link
Member

thehowl commented Jan 14, 2025

This is a recent feature in Go as well, so implementation of this feature is a non-priority but I think we can accept a PR.

@thehowl thehowl added this to the ⏭️Next after mainnet milestone Jan 14, 2025
@thehowl thehowl added 🌱 feature New update to Gno and removed 🐞 bug Something isn't working labels Jan 14, 2025
@thehowl thehowl changed the title gnovm: Slice-to-Array Casting Limitation cannot convert slice to array Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related 🌱 feature New update to Gno
Projects
Status: Triage
Development

No branches or pull requests

2 participants