From 822669c6580f4faf6dd88de3ec437744e6276093 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 3 Jan 2014 14:08:12 -0800 Subject: [PATCH] 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 --- go/importer/export.go | 2 ++ go/importer/import.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/go/importer/export.go b/go/importer/export.go index 9c5eddd5..bcc9982c 100644 --- a/go/importer/export.go +++ b/go/importer/export.go @@ -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()) } diff --git a/go/importer/import.go b/go/importer/import.go index afc430f8..a1edc5b8 100644 --- a/go/importer/import.go +++ b/go/importer/import.go @@ -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") }