]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: Don't accept qualified names as literal keys
authorDaniel Morsing <daniel.morsing@gmail.com>
Sun, 7 Oct 2012 14:47:53 +0000 (16:47 +0200)
committerDaniel Morsing <daniel.morsing@gmail.com>
Sun, 7 Oct 2012 14:47:53 +0000 (16:47 +0200)
Fixes #4067.

R=golang-dev, minux.ma, dave, rsc
CC=golang-dev
https://golang.org/cl/6622056

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

index 74ed84b134e7a847ed82df2c5a754c2c121bf18c..e84b45f3893a53b1bc0d71a91920b7679cd4c563 100644 (file)
@@ -2136,7 +2136,7 @@ typecheckcomplit(Node **np)
        Node *l, *n, *r, **hash;
        NodeList *ll;
        Type *t, *f;
-       Sym *s;
+       Sym *s, *s1;
        int32 lno;
        ulong nhash;
        Node *autohash[101];
@@ -2302,9 +2302,11 @@ typecheckcomplit(Node **np)
                                // 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 && exportname(s->name))
-                                       s = lookup(s->name);
-
+                               if(s->pkg != localpkg && exportname(s->name)) {
+                                       s1 = lookup(s->name);
+                                       if(s1->origpkg == s->pkg)
+                                               s = s1;
+                               }
                                f = lookdot1(nil, s, t, t->type, 0);
                                if(f == nil) {
                                        yyerror("unknown %T field '%S' in struct literal", t, s);
diff --git a/test/fixedbugs/bug462.go b/test/fixedbugs/bug462.go
new file mode 100644 (file)
index 0000000..6434255
--- /dev/null
@@ -0,0 +1,19 @@
+// errorcheck
+
+// Copyright 2012 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 "os"
+
+type T struct {
+       File int
+}
+
+func main() {
+       _ = T {
+               os.File: 1, // ERROR "unknown T field"
+       }
+}