golang/go

x/tools/gopls: Package.Path called on nil Package in AddTestForFunc

Closed this issue · 2 comments

#!stacks
"sigpanic" && "types.(*Package).Path" && "AddTestForFunc.func4"

Issue created by stacks.

Another case of calling Obj().Pkg().Path() without checking for nil (unsafe.Pointer or builtin-in error):

	var isContextType = func(t types.Type) bool {
		named, ok := t.(*types.Named)
		if !ok {
			return false
		}
		return named.Obj().Pkg().Path() == "context" && named.Obj().Name() == "Context" <--- SEGV here
	}

This stack 651rTQ was reported by telemetry:

golang.org/x/tools/gopls@v0.18.1 go1.23.6 darwin/arm64 other (1)

Change https://go.dev/cl/673198 mentions this issue: gopls/internal/golang: AddTest: fix types.Package.Path nil panic