]> Cypherpunks repositories - gostls13.git/commitdiff
gc: import dot shadowing bug
authorRuss Cox <rsc@golang.org>
Mon, 26 Jul 2010 21:21:39 +0000 (14:21 -0700)
committerRuss Cox <rsc@golang.org>
Mon, 26 Jul 2010 21:21:39 +0000 (14:21 -0700)
R=ken2
CC=golang-dev
https://golang.org/cl/1873047

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

index 85a63124ae184594d082f716d1a196fa8e03abb5..39e577404829aaca2caff78e4971150325c80857 100644 (file)
@@ -1781,6 +1781,11 @@ typecheckcomplit(Node **np)
                                        typecheck(&l->right, Erv);
                                        continue;
                                }
+                               // Sym might have resolved to name in other top-level
+                               // package, because of import dot.  Redirect to correct sym
+                               // before we do the lookup.
+                               if(s->pkg != localpkg)
+                                       s = lookup(s->name);
                                l->left = newname(s);
                                l->left->typecheck = 1;
                                f = lookdot1(s, t, t->type, 0);
diff --git a/test/fixedbugs/bug295.go b/test/fixedbugs/bug295.go
new file mode 100644 (file)
index 0000000..fec2351
--- /dev/null
@@ -0,0 +1,17 @@
+// $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
+
+import . "testing"  // defines top-level T
+
+type S struct {
+       T int
+}
+
+func main() {
+       _ = &S{T: 1}    // should work
+}