1
0
mirror of https://github.com/golang/go synced 2024-11-25 16:07:56 -07:00

cmd/gc: Don't export embedded builtins

Fixes #4124.

R=golang-dev, dave, minux.ma, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6543057
This commit is contained in:
Daniel Morsing 2012-10-07 06:53:57 +02:00
parent 01ddc8bd9a
commit a45777fe99
9 changed files with 65 additions and 6 deletions

View 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;

View 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));

View 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);

View 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;

View 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);

View File

@ -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
}

View File

@ -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"
}

10
test/fixedbugs/bug460.go Normal file
View File

@ -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

23
test/fixedbugs/bug461.go Normal file
View File

@ -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")
}
}