]> Cypherpunks repositories - gostls13.git/commitdiff
gc: multiple return value at top-level invoked multiple times
authorRuss Cox <rsc@golang.org>
Tue, 19 Jan 2010 01:00:38 +0000 (17:00 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 19 Jan 2010 01:00:38 +0000 (17:00 -0800)
Fixes #402.

R=ken2
CC=golang-dev
https://golang.org/cl/186214

src/cmd/gc/sinit.c
test/fixedbugs/bug244.go [new file with mode: 0644]

index b1160d3d482f29dc436d65c76cb0577a11432fc1..1b618fddb2ae9100177572b227d5eca0f5c57fcf 100644 (file)
@@ -90,12 +90,18 @@ init1(Node *n, NodeList **out)
                        break;
                
                case OAS2FUNC:
+                       if(n->defn->initorder)
+                               break;
+                       n->defn->initorder = 1;
                        for(l=n->defn->rlist; l; l=l->next)
                                init1(l->n, out);
                        *out = list(*out, n->defn);
                        break;
                
                case OAS2MAPR:
+                       if(n->defn->initorder)
+                               break;
+                       n->defn->initorder = 1;
                        for(l=n->defn->rlist; l; l=l->next)
                                init1(l->n, out);
                        *out = list(*out, n->defn);
diff --git a/test/fixedbugs/bug244.go b/test/fixedbugs/bug244.go
new file mode 100644 (file)
index 0000000..26db787
--- /dev/null
@@ -0,0 +1,30 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// Copyright 2010 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 nf int
+var ng int
+
+func f() (int, int, int) {
+       nf++
+       return 1, 2, 3
+}
+
+func g() int {
+       ng++
+       return 4
+}
+
+var x, y, z = f()
+var m = make(map[int]int)
+var v, ok = m[g()]
+
+func main() {
+       if x != 1 || y != 2 || z != 3 || nf != 1 || v != 0 || ok != false || ng != 1 {
+               panic("x=", x, " y=", y, " z=", z, " nf=", nf, " v=", v, " ok=", ok, " ng=", ng)
+       }
+}