Repository: go
Issue: x/tools/gopls: "diagnostic location is not among files of package: %s" bug (with analyzer SA4023)
Labels: NeedsInvestigation,gopls,Tools,gopls/telemetry-wins

```
#!stacks
"bug.Errorf" && "cache.(*action).exec.func2:+48"
```
Issue created by [stacks](https://pkg.go.dev/golang.org/x/tools/gopls/internal/telemetry/cmd/stacks).

```go
if mapper == nil {
			// The start position was not among the package's parsed
			// Go files, indicating that the analyzer added new files
			// to the FileSet.
			//
			// For example, the cgocall analyzer re-parses and
			// type-checks some of the files in a special environment;
			// and asmdecl and other low-level runtime analyzers call
			// ReadFile to parse non-Go files.
			// (This is a supported feature, documented at go/analysis.)
			//
			// In principle these files could be:
			//
			// - OtherFiles (non-Go files such as asm).
			//   However, we set Pass.OtherFiles=[] because
			//   gopls won't service "diagnose" requests
			//   for non-Go files, so there's no point
			//   reporting diagnostics in them.
			//
			// - IgnoredFiles (files tagged for other configs).
			//   However, we set Pass.IgnoredFiles=[] because,
			//   in most cases, zero-config gopls should create
			//   another view that covers these files.
			//
			// - Referents of //line directives, as in cgo packages.
			//   The file names in this case are not known a priori.
			//   gopls generally tries to avoid honoring line directives,
			//   but analyzers such as cgocall may honor them.
			//
			// In short, it's unclear how this can be reached
			// other than due to an analyzer bug.
			return protocol.Location{}, bug.Errorf("diagnostic location is not among files of package: %s", tokFile.Name())
}
```

The analyzer that reported the diagnostic is staticcheck's [SA4023](https://github.com/dominikh/go-tools/blob/v0.5.1/staticcheck/sa4023/sa4023.go), but all its calls to Report look fine.

This stack `dlmz3w` was [reported by telemetry](https://storage.googleapis.com/prod-telemetry-merged/2024-12-10.json):

- `gopls/bug`
- [`golang.org/x/tools/gopls/internal/util/bug.report:+35`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0-pre.3:gopls/internal/util/bug/bug.go;l=109)
- [`golang.org/x/tools/gopls/internal/util/bug.Errorf:+2`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0-pre.3:gopls/internal/util/bug/bug.go;l=61)
- [`golang.org/x/tools/gopls/internal/cache.(*action).exec.func2:+48`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0-pre.3:gopls/internal/cache/analysis.go;l=1088)
- [`golang.org/x/tools/gopls/internal/cache.toGobDiagnostic:+22`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0-pre.3:gopls/internal/cache/analysis.go;l=1355)
- [`golang.org/x/tools/gopls/internal/cache.(*action).exec.func3:+1`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0-pre.3:gopls/internal/cache/analysis.go;l=1141)
- `honnef.co/go/tools/analysis/report.Report:+40`
- `honnef.co/go/tools/staticcheck/sa4023.run:+100`
- [`golang.org/x/tools/gopls/internal/cache.(*action).exec.func7:+31`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0-pre.3:gopls/internal/cache/analysis.go;l=1216)
- [`golang.org/x/tools/gopls/internal/cache.(*action).exec:+277`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0-pre.3:gopls/internal/cache/analysis.go;l=1217)
- [`golang.org/x/tools/gopls/internal/cache.execActions.func1.1:+2`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0-pre.3:gopls/internal/cache/analysis.go;l=916)
- [`sync.(*Once).doSlow:+5`](https://cs.opensource.google/go/go/+/go1.23.2:src/sync/once.go;l=76)
- [`sync.(*Once).Do:=67`](https://cs.opensource.google/go/go/+/go1.23.2:src/sync/once.go;l=67)
- [`golang.org/x/tools/gopls/internal/cache.execActions.func1:+2`](https://cs.opensource.google/go/x/tools/+/gopls/v0.17.0-pre.3:gopls/internal/cache/analysis.go;l=914)
- `runtime.goexit:+0`
```
golang.org/x/tools/gopls@v0.17.0-pre.3 go1.23.2 linux/amd64 vscode (1)
```