go.tools/importer: fix field package for anonymous fields

Anonymous field names are emitted as "" in the export data
since the actual name can be reconstructed easily from the
field's type name. But "" names are not exported names and
thus the respective qualified name emits complete package
information even if the actual field name is exported. Fix
the package upon import.

R=adonovan
CC=golang-codereviews
https://golang.org/cl/42090044
This commit is contained in:
Robert Griesemer 2014-01-03 14:08:12 -08:00
parent df08273253
commit 822669c658
2 changed files with 6 additions and 0 deletions

View File

@ -350,6 +350,8 @@ func (p *exporter) field(f *types.Var) {
name = f.Name()
}
// qualifiedName will always emit the field package for
// anonymous fields because "" is not an exported name.
p.qualifiedName(f.Pkg(), name)
p.typ(f.Type())
}

View File

@ -336,6 +336,10 @@ func (p *importer) field() *types.Var {
case *types.Named:
obj := typ.Obj()
name = obj.Name()
// correct the field package for anonymous fields
if exported(name) {
pkg = p.pkgList[0]
}
default:
panic("anonymous field expected")
}