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

Mixed keyed and unkeyed elements in a slice are not supported #3464

Open
piux2 opened this issue Jan 9, 2025 · 0 comments
Open

Mixed keyed and unkeyed elements in a slice are not supported #3464

piux2 opened this issue Jan 9, 2025 · 0 comments
Assignees
Labels
🐞 bug Something isn't working

Comments

@piux2
Copy link
Contributor

piux2 commented Jan 9, 2025

Description

Mixed keyed and unkeyed elements in a slice should be allowed.

According to the go specs https://go.dev/ref/spec

For array and slice literals the following rules apply:
- Each element has an associated integer index marking its position in the array.
- An element without a key uses the previous element's index plus one. If the first element has no key, its index is zero.

Your environment

  • Go version (example: go1.22)
  • OS and CPU architecture (MacOS/ARM64)
  • Gno commit hash causing the issue (6472eea)

Steps to reproduce

// slice4.gno
package main

func main() {
	var x = []int{4: 14, 25, 1: 33, 34}
	println(len(x), x[2])
}

// Output:
//  6 34
  • add above file to gnovm/tests/files/slice/slice4.gno
  • go test gnovm/pkg/gnolang/files_test.go -run 'TestFiles/slice/'

Expected behaviour

It should pass, and the output should be 6 34

https://go.dev/play/p/QWy6BXtDJZV?v=goprev

Actual behaviour

--- FAIL: TestFiles (0.04s)
--- FAIL: TestFiles/slice/slice4.gno (0.00s)
panic: slice composite literal cannot mix keyed and unkeyed elements [recovered]
panic: slice composite literal cannot mix keyed and unkeyed elements [recovered]
panic: interface conversion: gnolang.Stmt is *gnolang.ValueDecl, not *gnolang.bodyStmt [recovered]
panic: interface conversion: gnolang.Stmt is *gnolang.ValueDecl, not *gnolang.bodyStmt

@piux2 piux2 added the 🐞 bug Something isn't working label Jan 9, 2025
@piux2 piux2 self-assigned this Jan 9, 2025
@piux2 piux2 changed the title mixed keyed and un-keyed elements elements in slice are not supported mixed keyed and un-keyed elements in a slice are not supported Jan 9, 2025
@piux2 piux2 changed the title mixed keyed and un-keyed elements in a slice are not supported Mixed keyed and unkeyed elements in a slice are not supported Jan 9, 2025
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
Status: Triage
Development

No branches or pull requests

1 participant