Skip to content

Commit bc8c84c

Browse files
committed
gopls/internal/golang: AddTest: fix types.Package.Path nil panic
Also, simplify isContextType by using a library function. Fixes golang/go#73687 Change-Id: Ic2483f26d15560bbfd69ce53f0c348343b6c080c Reviewed-on: https://go-review.googlesource.com/c/tools/+/673198 Reviewed-by: Hongxiang Jiang <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent b37bd0b commit bc8c84c

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

gopls/internal/golang/addtest.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"golang.org/x/tools/gopls/internal/protocol"
2929
goplsastutil "golang.org/x/tools/gopls/internal/util/astutil"
3030
"golang.org/x/tools/gopls/internal/util/moremaps"
31+
"golang.org/x/tools/internal/analysisinternal"
3132
"golang.org/x/tools/internal/imports"
3233
"golang.org/x/tools/internal/typesinternal"
3334
)
@@ -480,12 +481,8 @@ func AddTestForFunc(ctx context.Context, snapshot *cache.Snapshot, loc protocol.
480481
},
481482
}
482483

483-
var isContextType = func(t types.Type) bool {
484-
named, ok := t.(*types.Named)
485-
if !ok {
486-
return false
487-
}
488-
return named.Obj().Pkg().Path() == "context" && named.Obj().Name() == "Context"
484+
isContextType := func(t types.Type) bool {
485+
return analysisinternal.IsTypeNamed(t, "context", "Context")
489486
}
490487

491488
for i := range sig.Params().Len() {

0 commit comments

Comments
 (0)