Skip to content

x/tools/gopls: "diagnostic location is not among files of package: %s" assertion is unjustified for Diagnostic.Related #70791

@adonovan

Description

@adonovan
#!stacks
"bug.Errorf" && "cache.(*action).exec.func2:+48"

Issue created by stacks.

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, but all its calls to Report look fine.

This stack dlmz3w was reported by telemetry:

golang.org/x/tools/[email protected] go1.23.2 linux/amd64 vscode (1)

Dups: ARI9LQ xuqd0A UM4FBg

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/telemetry-wins

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions