mirror of
https://github.com/golang/go
synced 2024-11-18 11:14:39 -07:00
go/gcimporter15: backport compiler exporter fix for golang/go#15514
Code from https://go-review.googlesource.com/#/c/27639/ . Remain backward-compatible with possibly installed packages that remain in Go1.6 format. Change-Id: If424e7a881c81bbfcacf38c0946542793c406abd Reviewed-on: https://go-review.googlesource.com/27640 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
2bbdb4568e
commit
b2560d12f6
@ -455,8 +455,7 @@ func (p *exporter) method(m *types.Func) {
|
||||
p.paramList(sig.Results(), false)
|
||||
}
|
||||
|
||||
// fieldName is like qualifiedName but it doesn't record the package
|
||||
// for blank (_) or exported names.
|
||||
// fieldName is like qualifiedName but it doesn't record the package for exported names.
|
||||
func (p *exporter) fieldName(f *types.Var) {
|
||||
name := f.Name()
|
||||
|
||||
@ -468,12 +467,12 @@ func (p *exporter) fieldName(f *types.Var) {
|
||||
base = ptr.Elem()
|
||||
}
|
||||
if named, ok := base.(*types.Named); ok && !named.Obj().Exported() {
|
||||
name = "?"
|
||||
// anonymous field with unexported base type name
|
||||
name = "?" // unexported name to force export of package
|
||||
}
|
||||
}
|
||||
|
||||
p.string(name)
|
||||
if name == "?" || name != "_" && !f.Exported() {
|
||||
if !f.Exported() {
|
||||
p.pkg(f.Pkg(), false)
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ type importer struct {
|
||||
data []byte
|
||||
path string
|
||||
buf []byte // for reading strings
|
||||
version int
|
||||
|
||||
// object lists
|
||||
strList []string // in order of appearance
|
||||
@ -76,12 +77,14 @@ func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []
|
||||
if s := p.string(); s != go17version {
|
||||
return p.read, nil, fmt.Errorf("importer: unknown export data format: %s (imported package compiled with old compiler?)", s)
|
||||
}
|
||||
p.version = 0
|
||||
} else {
|
||||
// Go1.8 extensible encoding
|
||||
const exportVersion = "version 1"
|
||||
if s := p.rawStringln(b); s != exportVersion {
|
||||
return p.read, nil, fmt.Errorf("importer: unknown export data format: %s (imported package compiled with old compiler?)", s)
|
||||
}
|
||||
p.version = 1
|
||||
p.debugFormat = p.rawStringln(p.rawByte()) == "debug"
|
||||
p.trackAllTypes = p.int() != 0
|
||||
p.posInfoFormat = p.int() != 0
|
||||
@ -532,19 +535,20 @@ func (p *importer) method(parent *types.Package) *types.Func {
|
||||
}
|
||||
|
||||
func (p *importer) fieldName(parent *types.Package) (*types.Package, string) {
|
||||
name := p.string()
|
||||
pkg := parent
|
||||
if pkg == nil {
|
||||
// use the imported package instead
|
||||
pkg = p.pkgList[0]
|
||||
}
|
||||
name := p.string()
|
||||
if name == "" {
|
||||
return pkg, "" // anonymous
|
||||
if p.version < 1 && name == "_" {
|
||||
// versions < 1 don't export a package for _ fields
|
||||
// TODO: remove once versions are not supported anymore
|
||||
return pkg, name
|
||||
}
|
||||
if name == "?" || name != "_" && !exported(name) {
|
||||
// explicitly qualified field
|
||||
if name != "" && !exported(name) {
|
||||
if name == "?" {
|
||||
name = "" // anonymous
|
||||
name = ""
|
||||
}
|
||||
pkg = p.pkg()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user