Repository: go
Issue: x/tools/gopls: Completion: SIGSEGV in scorePenalty
Labels: NeedsInvestigation,gopls,Tools,gopls/telemetry-wins,BugReport

```
#!stacks
"sigpanic"&& "completion.(*deepCompletionState).scorePenalty:+2"
```
Issue created by [stacks](https://pkg.go.dev/golang.org/x/tools/gopls/internal/telemetry/cmd/stacks).
```go

// scorePenalty computes a deep candidate score penalty. A candidate is
// penalized based on depth to favor shallower candidates. We also give a
// slight bonus to unexported objects and a slight additional penalty to
// function objects.
func (s *deepCompletionState) scorePenalty(cand *candidate) float64 {
	var deepPenalty float64
	for _, dc := range cand.path { <-- sigpanic
		deepPenalty++

		if !dc.Exported() {
			deepPenalty -= 0.1
		}

		if _, isSig := dc.Type().Underlying().(*types.Signature); isSig {
			deepPenalty += 0.1
		}
	}

	// Normalize penalty to a max depth of 10.
	return deepPenalty / 10
}
```
This stack `AZThiA` was [reported by telemetry](https://storage.googleapis.com/prod-telemetry-merged/2025-01-18.json):

- `crash/crash`
- [`runtime.gopanic:+69`](https://cs.opensource.google/go/go/+/go1.23.4:src/runtime/panic.go;l=804)
- `runtime.panicmem:=262`
- [`runtime.sigpanic:+19`](https://cs.opensource.google/go/go/+/go1.23.4:src/runtime/signal_unix.go;l=917)
- [`golang.org/x/tools/gopls/internal/golang/completion.(*deepCompletionState).scorePenalty:+2`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.1:gopls/internal/golang/completion/deep_completion.go;l=55)
- [`golang.org/x/tools/gopls/internal/golang/completion.(*completer).addCandidate:+37`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.1:gopls/internal/golang/completion/deep_completion.go;l=287)
- [`golang.org/x/tools/gopls/internal/golang/completion.(*completer).deepSearch:+71`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.1:gopls/internal/golang/completion/deep_completion.go;l=180)
- [`golang.org/x/tools/gopls/internal/golang/completion.Completion:+158`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.1:gopls/internal/golang/completion/completion.go;l=659)
- [`golang.org/x/tools/gopls/internal/server.(*server).Completion:+19`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.1:gopls/internal/server/completion.go;l=43)
- [`golang.org/x/tools/gopls/internal/protocol.serverDispatch:+193`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.1:gopls/internal/protocol/tsserver.go;l=363)
- [`golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3:+5`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.1:gopls/internal/protocol/protocol.go;l=160)
- [`golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4:+52`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.1:gopls/internal/lsprpc/lsprpc.go;l=509)
- [`golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1:+2`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.1:internal/jsonrpc2/handler.go;l=35)
- [`golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2:+3`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.1:internal/jsonrpc2/handler.go;l=104)
- `runtime.goexit:+0`
```
golang.org/x/tools/gopls@v0.17.1 go1.23.4 linux/amd64 vscode (1)
```