mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:08 +00: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:
parent
01ddc8bd9a
commit
a45777fe99
9 changed files with 65 additions and 6 deletions
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
9
test/fixedbugs/bug460.dir/a.go
Normal file
9
test/fixedbugs/bug460.dir/a.go
Normal 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
|
||||
}
|
14
test/fixedbugs/bug460.dir/b.go
Normal file
14
test/fixedbugs/bug460.dir/b.go
Normal 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
10
test/fixedbugs/bug460.go
Normal 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
23
test/fixedbugs/bug461.go
Normal 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")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue