Skip to content

Commit 246a69f

Browse files
stamblerrebradfitz
authored andcommitted
go/gcexportdata: use IExportData when writing gcexportdata
Updates golang/go#28260 Change-Id: Id0ef98e1599fbef4dd67ba23c20ddb8bc4d33228 Reviewed-on: https://go-review.googlesource.com/c/tools/+/198742 Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 9901302 commit 246a69f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

go/gcexportdata/gcexportdata.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func Read(in io.Reader, fset *token.FileSet, imports map[string]*types.Package,
100100
// Write writes encoded type information for the specified package to out.
101101
// The FileSet provides file position information for named objects.
102102
func Write(out io.Writer, fset *token.FileSet, pkg *types.Package) error {
103-
b, err := gcimporter.BExportData(fset, pkg)
103+
b, err := gcimporter.IExportData(fset, pkg)
104104
if err != nil {
105105
return err
106106
}

go/internal/gcimporter/iimport.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,20 @@ func IImportData(fset *token.FileSet, imports map[string]*types.Package, data []
143143
p.pkgIndex[pkg] = nameIndex
144144
pkgList[i] = pkg
145145
}
146+
if len(pkgList) == 0 {
147+
errorf("no packages found for %s", path)
148+
panic("unreachable")
149+
}
146150
var localpkg *types.Package
147151
for _, pkg := range pkgList {
148152
if pkg.Path() == path {
149153
localpkg = pkg
154+
break
150155
}
151156
}
157+
if localpkg == nil {
158+
localpkg = pkgList[0]
159+
}
152160

153161
names := make([]string, 0, len(p.pkgIndex[localpkg]))
154162
for name := range p.pkgIndex[localpkg] {

0 commit comments

Comments
 (0)