testSlice mentions printLen, printLen mentions testSlice. The specification explicitly forbids such init cycles.
On Fri, 22 Oct 2021, 19:51 dana...@gmail.com, <danau...@gmail.com> wrote: > Why do I get an initialization loop in the following program? > > ```go > package main > import "fmt" > var testSlice = []func(){printLen} > func printLen() { > fmt.Print(len(testSlice)) > } > func main() { > printLen() > } > ``` > Playground Link: https://play.golang.org/p/tJenMMaWex6 > Using go1.17.2 > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/505a239c-441f-41f5-bcc3-93b2fa8f2561n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/505a239c-441f-41f5-bcc3-93b2fa8f2561n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA40n-V7suhdtkR0eCruGYsn%2B8T5dqoQFRf3iQOg8ygC6NEtEQ%40mail.gmail.com.