]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: Don't export embedded builtins
authorDaniel Morsing <daniel.morsing@gmail.com>
Sun, 7 Oct 2012 04:53:57 +0000 (06:53 +0200)
committerDaniel Morsing <daniel.morsing@gmail.com>
Sun, 7 Oct 2012 04:53:57 +0000 (06:53 +0200)
Fixes #4124.

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

src/cmd/gc/align.c
src/cmd/gc/dcl.c
src/cmd/gc/fmt.c
src/cmd/gc/lex.c
src/cmd/gc/reflect.c
test/fixedbugs/bug460.dir/a.go [new file with mode: 0644]
test/fixedbugs/bug460.dir/b.go [new file with mode: 0644]
test/fixedbugs/bug460.go [new file with mode: 0644]
test/fixedbugs/bug461.go [new file with mode: 0644]

index 36a33d48279d61189de90e7c2597f6b79a7e0684..2440a4b3e277536bc500c3ff77de0ce06d77c8d0 100644 (file)
@@ -607,7 +607,7 @@ typeinit(void)
                        fatal("typeinit: %s already defined", s->name);
 
                t = typ(etype);
-               t->sym = s;
+               t->sym = s1;
 
                dowidth(t);
                types[etype] = t;
index 1f50910526f58a21fcae08728d5bf72e78eb3b76..d090380d7eeadd62d25c2f6999cd15d4039c3001 100644 (file)
@@ -982,7 +982,7 @@ embedded(Sym *s)
                *utfrune(name, CenterDot) = 0;
        }
 
-       if(exportname(name) || s->pkg == builtinpkg)  // old behaviour, tests pass, but is it correct?
+       if(exportname(name))
                n = newname(lookup(name));
        else
                n = newname(pkglookup(name, s->pkg));
index c59d1b9fcd2024def99ee6a55a82afd9188373d4..5a1f6793013f63c2714d7a1587731f71a942e158 100644 (file)
@@ -1181,7 +1181,7 @@ exprfmt(Fmt *f, Node *n, int prec)
                                        t = l->n->left->type->type;
                                        if(t->sym == S)
                                                t = t->type;
-                                       fmtprint(f, " %T:%N", t, l->n->right);
+                                       fmtprint(f, " %hhS:%N", t->sym, l->n->right);
                                } else
                                        fmtprint(f, " %hhS:%N", l->n->left->sym, l->n->right);
 
index 6bf00161b716bad88e6d6b609044e0e056e0b74e..46728c904dd7125d60fc9d0c2fe32ebb5cd20167 100644 (file)
@@ -1831,16 +1831,16 @@ lexinit(void)
                if(etype != Txxx) {
                        if(etype < 0 || etype >= nelem(types))
                                fatal("lexinit: %s bad etype", s->name);
+                       s1 = pkglookup(syms[i].name, builtinpkg);
                        t = types[etype];
                        if(t == T) {
                                t = typ(etype);
-                               t->sym = s;
+                               t->sym = s1;
 
                                if(etype != TANY && etype != TSTRING)
                                        dowidth(t);
                                types[etype] = t;
                        }
-                       s1 = pkglookup(syms[i].name, builtinpkg);
                        s1->lexical = LNAME;
                        s1->def = typenod(t);
                        continue;
index ad1d8d86061af5690707c6fc0ed99974641e469a..8e4f0a4d276d124146b2604fcad61fd3c551fea8 100644 (file)
@@ -866,7 +866,10 @@ ok:
                                        ot = dgopkgpath(s, ot, t1->sym->pkg);
                        } else {
                                ot = dgostringptr(s, ot, nil);
-                               ot = dgostringptr(s, ot, nil);
+                               if(t1->type->sym != S && t1->type->sym->pkg == builtinpkg)
+                                       ot = dgopkgpath(s, ot, localpkg);
+                               else
+                                       ot = dgostringptr(s, ot, nil);
                        }
                        ot = dsymptr(s, ot, dtypesym(t1->type), 0);
                        ot = dgostrlitptr(s, ot, t1->note);
diff --git a/test/fixedbugs/bug460.dir/a.go b/test/fixedbugs/bug460.dir/a.go
new file mode 100644 (file)
index 0000000..02a287b
--- /dev/null
@@ -0,0 +1,9 @@
+// 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 a
+
+type Foo struct {
+       int
+}
diff --git a/test/fixedbugs/bug460.dir/b.go b/test/fixedbugs/bug460.dir/b.go
new file mode 100644 (file)
index 0000000..1868afe
--- /dev/null
@@ -0,0 +1,14 @@
+// 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 b
+
+import "./a"
+
+var x a.Foo
+
+func main() {
+       x.int = 20 // ERROR "unexported field"
+}
+
diff --git a/test/fixedbugs/bug460.go b/test/fixedbugs/bug460.go
new file mode 100644 (file)
index 0000000..79234a3
--- /dev/null
@@ -0,0 +1,10 @@
+// errorcheckdir
+
+// 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.
+
+// part one of issue 4124. Make sure that the compiler rejects access attempts.
+
+package ignored
+
diff --git a/test/fixedbugs/bug461.go b/test/fixedbugs/bug461.go
new file mode 100644 (file)
index 0000000..f0f7b0e
--- /dev/null
@@ -0,0 +1,23 @@
+// run
+
+// 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.
+
+// part two of issue 4124. Make sure reflect doesn't mark the field as exported.
+
+package main
+
+import "reflect"
+
+var T struct {
+       int
+}
+
+func main() {
+       v := reflect.ValueOf(&T)
+       v = v.Elem().Field(0)
+       if v.CanSet() {
+               panic("int should be unexported")
+       }
+}