1
0
mirror of https://github.com/golang/go synced 2024-11-25 20:57:57 -07:00

Fix npe from importerOf[p]

This commit is contained in:
xzhang39 2024-10-10 20:55:14 -07:00
parent d76568d7ee
commit c5a16256d1

View File

@ -546,13 +546,13 @@ func recompileForTest(pmain, preal, ptest, pxtest *Package) *PackageError {
// by x, and then we reverse it.
var stk ImportStack
for p != nil {
tokenPositions := []token.Position{}
if importerOf[p].Internal.Build != nil {
tokenPositions = importerOf[p].Internal.Build.ImportPos[p.ImportPath]
importer, ok := importerOf[p]
if importer == nil && ok { // we set importerOf[p] == nil for the initial set of packages p that are imports of ptest
importer = ptest
}
stk = append(stk, ImportInfo{
Pkg: p.ImportPath,
Pos: extractFirstImport(tokenPositions),
Pos: extractFirstImport(importer.Internal.Build.ImportPos[p.ImportPath]),
})
p = importerOf[p]
}