[gopls-release-branch.0.17] gopls/internal/cache/testfuncs: fix crash with *error argument The test detection logic incorrectly assumes that named types have a non-nil package, which is not true for Error (as we've encountered numerous times). Add the missing nil check. Fixes golang/go#70927 Change-Id: Ibdf483304b53ce219123e820d74acd4f9d12d710 Reviewed-on: https://go-review.googlesource.com/c/tools/+/637815 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Robert Findley <rfindley@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> (cherry picked from commit dcc725c94c3520b24b7cd74fa066d2a93d9dd25c) Reviewed-on: https://go-review.googlesource.com/c/tools/+/637736
diff --git a/gopls/internal/cache/testfuncs/tests.go b/gopls/internal/cache/testfuncs/tests.go index cfc7daa..fca25e5 100644 --- a/gopls/internal/cache/testfuncs/tests.go +++ b/gopls/internal/cache/testfuncs/tests.go
@@ -281,7 +281,7 @@ } named, ok := ptr.Elem().(*types.Named) - if !ok || named.Obj().Pkg().Path() != "testing" { + if !ok || named.Obj().Pkg() == nil || named.Obj().Pkg().Path() != "testing" { return nil, false }
diff --git a/gopls/internal/test/integration/workspace/packages_test.go b/gopls/internal/test/integration/workspace/packages_test.go index 106734a..7ee19bc 100644 --- a/gopls/internal/test/integration/workspace/packages_test.go +++ b/gopls/internal/test/integration/workspace/packages_test.go
@@ -124,6 +124,7 @@ package foo import "testing" func TestFoo(t *testing.T) +func Issue70927(*error) -- foo2_test.go -- package foo_test