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

len of array with function calls should not be constant #3701

Open
thehowl opened this issue Feb 7, 2025 · 0 comments · May be fixed by #3714
Open

len of array with function calls should not be constant #3701

thehowl opened this issue Feb 7, 2025 · 0 comments · May be fixed by #3714
Assignees
Labels
🐞 bug Something isn't working 📦 🤖 gnovm Issues or PRs gnovm related

Comments

@thehowl
Copy link
Member

thehowl commented Feb 7, 2025

// You can edit this code!
// Click here and start typing.
package main

import "fmt"

func main() {
	const a = len([1]int{
		func() int { println("hey!!"); return 1 }(),
	})
	fmt.Println("Hello", a)
}

this code fails in the go playground, because a is not a constant expression:

The expression len(s) is constant if s is a string constant. The expressions len(s) and cap(s) are constants if the type of s is an array or pointer to an array and the expression s does not contain channel receives or (non-constant) function calls; in this case s is not evaluated. Otherwise, invocations of len and cap are not constant and s is evaluated.

however, it is correctly parsed and succeeds in gno.

related #3600

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: Triage
Development

Successfully merging a pull request may close this issue.

2 participants