]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix import width bug
authorRuss Cox <rsc@golang.org>
Mon, 25 Apr 2011 16:08:48 +0000 (12:08 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 25 Apr 2011 16:08:48 +0000 (12:08 -0400)
Fixes #1705.

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

src/cmd/5g/cgen.c
src/cmd/6g/cgen.c
src/cmd/8g/cgen.c
src/cmd/gc/dcl.c
src/cmd/gc/walk.c
test/fixedbugs/bug335.dir/a.go [new file with mode: 0644]
test/fixedbugs/bug335.dir/b.go [new file with mode: 0644]
test/fixedbugs/bug335.go [new file with mode: 0644]

index 032409baee3d6b7657843d7fcffccf55c63ecd9f..e0fc7682151b8c3292e6fa818db31e9ff1f09129 100644 (file)
@@ -43,6 +43,8 @@ cgen(Node *n, Node *res)
        }
 
        if(isfat(n->type)) {
+               if(n->type->width < 0)
+                       fatal("forgot to compute width for %T", n->type);
                sgen(n, res, n->type->width);
                goto ret;
        }
index 47f3374f530201081d4ea4ae16b28602125b80bc..048174e0869efc10c6038dd4576fd24f50f7d38c 100644 (file)
@@ -47,6 +47,8 @@ cgen(Node *n, Node *res)
        }
 
        if(isfat(n->type)) {
+               if(n->type->width < 0)
+                       fatal("forgot to compute width for %T", n->type);
                sgen(n, res, n->type->width);
                goto ret;
        }
index 9c326e8ef1a95e27c63c05d4dafec1b5ef9344fa..036188fec4a7085253ae1e34771dcfaf75ef204f 100644 (file)
@@ -78,6 +78,8 @@ cgen(Node *n, Node *res)
 
        // structs etc get handled specially
        if(isfat(n->type)) {
+               if(n->type->width < 0)
+                       fatal("forgot to compute width for %T", n->type);
                sgen(n, res, n->type->width);
                return;
        }
index bf164b3f43d80aece4ea8897acb37a44f30e675f..80cb74408adc8dc93ea0cd39e455044aa763bf08 100644 (file)
@@ -684,6 +684,10 @@ ok:
        pt->nod = n;
        pt->sym = n->sym;
        pt->sym->lastlineno = parserline();
+       pt->siggen = 0;
+       pt->printed = 0;
+       pt->deferwidth = 0;
+       pt->local = 0;
        declare(n, PEXTERN);
 
        checkwidth(pt);
index ae556ae3fb1ee144e8ec98c8bf28eca963bbb42d..bee3c25b0ddd7aa65d43c4fd80d128a1a8b3473d 100644 (file)
@@ -142,7 +142,9 @@ walkdeftype(Node *n)
        }
 
        // copy new type and clear fields
-       // that don't come along
+       // that don't come along.
+       // anything zeroed here must be zeroed in
+       // typedcl2 too.
        maplineno = n->type->maplineno;
        embedlineno = n->type->embedlineno;
        *n->type = *t;
diff --git a/test/fixedbugs/bug335.dir/a.go b/test/fixedbugs/bug335.dir/a.go
new file mode 100644 (file)
index 0000000..5a8112a
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2011 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 a
+
+import "./b"
+
+var Bar = b.Foo
diff --git a/test/fixedbugs/bug335.dir/b.go b/test/fixedbugs/bug335.dir/b.go
new file mode 100644 (file)
index 0000000..7428c2a
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2011 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 b
+
+type T interface{}
+
+func f() T { return nil }
+
+var Foo T = f()
diff --git a/test/fixedbugs/bug335.go b/test/fixedbugs/bug335.go
new file mode 100644 (file)
index 0000000..915b746
--- /dev/null
@@ -0,0 +1,10 @@
+// $G $D/$F.dir/b.go && $G $D/$F.dir/a.go
+// rm -f a.$A b.$A
+
+// Copyright 2011 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.
+
+// Issue 1705.
+
+unused (see script at top of file)