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)
|
p.paramList(sig.Results(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fieldName is like qualifiedName but it doesn't record the package
|
// fieldName is like qualifiedName but it doesn't record the package for exported names.
|
||||||
// for blank (_) or exported names.
|
|
||||||
func (p *exporter) fieldName(f *types.Var) {
|
func (p *exporter) fieldName(f *types.Var) {
|
||||||
name := f.Name()
|
name := f.Name()
|
||||||
|
|
||||||
|
@ -468,12 +467,12 @@ func (p *exporter) fieldName(f *types.Var) {
|
||||||
base = ptr.Elem()
|
base = ptr.Elem()
|
||||||
}
|
}
|
||||||
if named, ok := base.(*types.Named); ok && !named.Obj().Exported() {
|
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)
|
p.string(name)
|
||||||
if name == "?" || name != "_" && !f.Exported() {
|
if !f.Exported() {
|
||||||
p.pkg(f.Pkg(), false)
|
p.pkg(f.Pkg(), false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ type importer struct {
|
||||||
data []byte
|
data []byte
|
||||||
path string
|
path string
|
||||||
buf []byte // for reading strings
|
buf []byte // for reading strings
|
||||||
|
version int
|
||||||
|
|
||||||
// object lists
|
// object lists
|
||||||
strList []string // in order of appearance
|
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 {
|
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)
|
return p.read, nil, fmt.Errorf("importer: unknown export data format: %s (imported package compiled with old compiler?)", s)
|
||||||
}
|
}
|
||||||
|
p.version = 0
|
||||||
} else {
|
} else {
|
||||||
// Go1.8 extensible encoding
|
// Go1.8 extensible encoding
|
||||||
const exportVersion = "version 1"
|
const exportVersion = "version 1"
|
||||||
if s := p.rawStringln(b); s != exportVersion {
|
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)
|
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.debugFormat = p.rawStringln(p.rawByte()) == "debug"
|
||||||
p.trackAllTypes = p.int() != 0
|
p.trackAllTypes = p.int() != 0
|
||||||
p.posInfoFormat = 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) {
|
func (p *importer) fieldName(parent *types.Package) (*types.Package, string) {
|
||||||
|
name := p.string()
|
||||||
pkg := parent
|
pkg := parent
|
||||||
if pkg == nil {
|
if pkg == nil {
|
||||||
// use the imported package instead
|
// use the imported package instead
|
||||||
pkg = p.pkgList[0]
|
pkg = p.pkgList[0]
|
||||||
}
|
}
|
||||||
name := p.string()
|
if p.version < 1 && name == "_" {
|
||||||
if name == "" {
|
// versions < 1 don't export a package for _ fields
|
||||||
return pkg, "" // anonymous
|
// TODO: remove once versions are not supported anymore
|
||||||
|
return pkg, name
|
||||||
}
|
}
|
||||||
if name == "?" || name != "_" && !exported(name) {
|
if name != "" && !exported(name) {
|
||||||
// explicitly qualified field
|
|
||||||
if name == "?" {
|
if name == "?" {
|
||||||
name = "" // anonymous
|
name = ""
|
||||||
}
|
}
|
||||||
pkg = p.pkg()
|
pkg = p.pkg()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue