Commit a45777fe authored by Daniel Morsing's avatar Daniel Morsing

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
parent 01ddc8bd
......@@ -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);
......
// 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
}
// 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"
}
// 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
// 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")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment