Skip to content

spec: no rule about loops in constant definition #13890

Open
@momchil-velikov

Description

@momchil-velikov

The compiler issues error constant definition loop for the following program:

package main
import "fmt"
const C = len(u)
func f() ([1]int, [C]float64) {
    return [...]int{1}, [...]float64{1.1}
}
var u, v = f()
func main() {
    fmt.Println(C, v)
}

In fact the value if C (resp. the type of u) does not depend on the type of the second return of f.

The same program is compiled successfully by gccgo.

PS. Another test case

package main
import "fmt"
const C = len(u)
type S struct {
    X [1]int
    Y [C]int
}
var s S
var u, v = s.X, s.Y
func main() {
    fmt.Println(C, v)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions