Skip to content

Commit

Permalink
gopls/internal/cache/testfuncs: fix crash with *error argument
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
findleyr authored and gopherbot committed Dec 19, 2024
1 parent 74dea82 commit dcc725c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gopls/internal/cache/testfuncs/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func testKind(sig *types.Signature) (*types.TypeName, bool) {
}

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
}

Expand Down
1 change: 1 addition & 0 deletions gopls/internal/test/integration/workspace/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func TestFoo2(t *testing.T)
package foo
import "testing"
func TestFoo(t *testing.T)
func Issue70927(*error)
-- foo2_test.go --
package foo_test
Expand Down

0 comments on commit dcc725c

Please sign in to comment.