@@ -26,6 +26,7 @@ type importer struct {
26
26
data []byte
27
27
path string
28
28
buf []byte // for reading strings
29
+ version int
29
30
30
31
// object lists
31
32
strList []string // in order of appearance
@@ -76,12 +77,14 @@ func BImportData(fset *token.FileSet, imports map[string]*types.Package, data []
76
77
if s := p .string (); s != go17version {
77
78
return p .read , nil , fmt .Errorf ("importer: unknown export data format: %s (imported package compiled with old compiler?)" , s )
78
79
}
80
+ p .version = 0
79
81
} else {
80
82
// Go1.8 extensible encoding
81
83
const exportVersion = "version 1"
82
84
if s := p .rawStringln (b ); s != exportVersion {
83
85
return p .read , nil , fmt .Errorf ("importer: unknown export data format: %s (imported package compiled with old compiler?)" , s )
84
86
}
87
+ p .version = 1
85
88
p .debugFormat = p .rawStringln (p .rawByte ()) == "debug"
86
89
p .trackAllTypes = p .int () != 0
87
90
p .posInfoFormat = p .int () != 0
@@ -532,19 +535,20 @@ func (p *importer) method(parent *types.Package) *types.Func {
532
535
}
533
536
534
537
func (p * importer ) fieldName (parent * types.Package ) (* types.Package , string ) {
538
+ name := p .string ()
535
539
pkg := parent
536
540
if pkg == nil {
537
541
// use the imported package instead
538
542
pkg = p .pkgList [0 ]
539
543
}
540
- name := p .string ()
541
- if name == "" {
542
- return pkg , "" // anonymous
544
+ if p .version < 1 && name == "_" {
545
+ // versions < 1 don't export a package for _ fields
546
+ // TODO: remove once versions are not supported anymore
547
+ return pkg , name
543
548
}
544
- if name == "?" || name != "_" && ! exported (name ) {
545
- // explicitly qualified field
549
+ if name != "" && ! exported (name ) {
546
550
if name == "?" {
547
- name = "" // anonymous
551
+ name = ""
548
552
}
549
553
pkg = p .pkg ()
550
554
}
0 commit comments