]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: fix initialization logic
authorKevin Vu <kevin.m.vu@gmail.com>
Mon, 4 Jan 2016 02:44:15 +0000 (18:44 -0800)
committerRuss Cox <rsc@golang.org>
Wed, 6 Jan 2016 02:10:52 +0000 (02:10 +0000)
Also add relevant test.

Fixes #13343.

Change-Id: Ib1e65af1d643d501de89adee3618eddbf6c69c9e
Reviewed-on: https://go-review.googlesource.com/18159
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/sinit.go
test/fixedbugs/bug13343.go [new file with mode: 0644]

index 6d88e45ea09483644b841055ffde3d079c4f0599..b7f7ea0bea2464dca2e092e838101c0d4d1016f7 100644 (file)
@@ -124,10 +124,10 @@ func init1(n *Node, out **NodeList) {
                        }
 
                case OAS2FUNC, OAS2MAPR, OAS2DOTTYPE, OAS2RECV:
-                       if defn.Initorder != InitNotStarted {
+                       if defn.Initorder == InitDone {
                                break
                        }
-                       defn.Initorder = InitDone
+                       defn.Initorder = InitPending
                        for l := defn.Rlist; l != nil; l = l.Next {
                                init1(l.N, out)
                        }
@@ -135,6 +135,7 @@ func init1(n *Node, out **NodeList) {
                                Dump("nonstatic", defn)
                        }
                        *out = list(*out, defn)
+                       defn.Initorder = InitDone
                }
        }
 
diff --git a/test/fixedbugs/bug13343.go b/test/fixedbugs/bug13343.go
new file mode 100644 (file)
index 0000000..4c30dac
--- /dev/null
@@ -0,0 +1,18 @@
+// errorcheck
+
+// Copyright 2015 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+var (
+       a, b = f() // ERROR "initialization loop|depends upon itself"
+       c    = b
+)
+
+func f() (int, int) {
+       return c, c
+}
+
+func main() {}