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:
parent
df08273253
commit
822669c658
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue