<p dir="auto">version: go version go1.5 darwin/amd64</p>
<p dir="auto">There is an example about variable initialization order in the go specs:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var (
    a = c + b
    b = f()
    c = f()
    d = 3
)

func f() int {
    d++
    return d
}
"><pre class="notranslate"><code class="notranslate">var (
    a = c + b
    b = f()
    c = f()
    d = 3
)

func f() int {
    d++
    return d
}

</code></pre></div>
<p dir="auto">the spec gives the initialization order is d, b, c, a. but the result of above example is not the same as the order spec gives.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="package main

import &quot;fmt&quot;

var (
    a = c + b
    b = f()
    c = f()
    d = 3
)

func f() int {
    d++
    return d
}

func main() {
    fmt.Println(a, b, c, d)
}"><pre class="notranslate"><code class="notranslate">package main

import "fmt"

var (
    a = c + b
    b = f()
    c = f()
    d = 3
)

func f() int {
    d++
    return d
}

func main() {
    fmt.Println(a, b, c, d)
}
</code></pre></div>
<p dir="auto">$go run example.go<br>
9 5 4 5</p>
<p dir="auto">according to the result, the actual init order should be d ,c ,b, a, not the same as the order in spec.</p>
<pre class="notranslate">$ 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: <a href="http://tip.golang.org/ref/spec#Package_initialization" rel="nofollow">http://tip.golang.org/ref/spec#Package_initialization</a></pre>