$ cat incorrect_init.go
package main
var (
a = p("a") + c + b
b = p("b") + f()
c = p("c") + f()
d = p("d") + 3
)
func f() int {
d++
return d
}
func p(s string) int {
println(s)
return 0
}
func main() {
println(a, b, c, d)
}
compiling and executing produces:
$ go run incorrect_init.go
d
c
b
a
9 5 4 5
But the correct order per the spec should be: d, b, c, a, with values 9, 4, 5, 5.
See: http://tip.golang.org/ref/spec#Package_initialization