You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
foo.go:4:8: error: initialization expressions for ‘b’ and ‘c’ depend upon each other
a, b = f()
^
foo.go:5:5: note: ‘c’ defined here
c = b
^
foo.go:5:5: error: initialization expressions for ‘c’ and ‘b’ depend upon each other
foo.go:4:8: note: ‘b’ defined here
a, b = f()
^
/home/iant/foo4.go:5:5: error: initialization expression for ‘c’ depends upon itself
c = b
^
Interestingly, swapping a and b does generate a cycle error:
package main
var (
b, a = f()
c = b
)
func f() (int, int) {
return c, c
}
func main() {}
cmd/compile/internal/gc/sinit.go:init1 is responsible for producing a list of definitions needing initialization code in dependency order, and for detecting initialization loops. init1 incorrectly marks function nodes as InitDone prior to traversing them.
Hence, in the first example, it will not detect the cycle on b because that involves traversing f twice:
a, b = f()
a
f()
f // mark f as done, but still traverse it
c
b
f()
// f has been marked done, so it is not checked and the cycle is undetected
In the second example, it will detect the cycle because f only has to be traversed once:
... as in the following program:
Related, though different issue here: #7320
go version go1.5.1 darwin/amd64
go version go1.5.1 linux/amd64
go version devel +af8cd3f Fri Nov 20 19:56:51 2015 +0000 linux/amd64
The text was updated successfully, but these errors were encountered: