Skip to content

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

Closed as not planned
Closed as not planned
@thehowl

Description

@thehowl
// 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

Metadata

Metadata

Assignees

Labels

📦 🤖 gnovmIssues or PRs gnovm related🐞 bugSomething isn't working

Type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions