From d76568d7ee410d8112dc4080321dd191243985dd Mon Sep 17 00:00:00 2001 From: xzhang39 Date: Tue, 8 Oct 2024 18:06:58 -0700 Subject: [PATCH] Fix a npe in test.go --- src/cmd/go/internal/load/test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/internal/load/test.go b/src/cmd/go/internal/load/test.go index a1a5a3ddf8..e40540b1de 100644 --- a/src/cmd/go/internal/load/test.go +++ b/src/cmd/go/internal/load/test.go @@ -546,9 +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] + } stk = append(stk, ImportInfo{ Pkg: p.ImportPath, - Pos: extractFirstImport(importerOf[p].Internal.Build.ImportPos[p.ImportPath]), + Pos: extractFirstImport(tokenPositions), }) p = importerOf[p] }