Skip to content

cmd/go: list reports same PackageError.Pos for each import of a given missing package #78183

@adonovan

Description

@adonovan

The following test case demonstrates a bug in the way go list reports errors for missing dependencies. (This may be the root cause of the downstream issue #73933 in gopls.)

$ cat cmd/go/testdata/script/golist-missingimport.txt
# This script demonstrates a bug(?) in go list's reporting of dependency errors:
# The location of the first import that encounters the error is used
# for all other imports. This confuses downstream tools, including go/packages and gopls.

env GOWORK=off

go list -e -f '{{range .DepsErrors}}package {{$.ImportPath}}: error at {{.Pos}}: {{.Err}}{{end}}' ./...

# The second assertion (in package q) fails; instead it reports p.go a second time.
stdout 'package example.com/test/p: error at p/p.go:3:8: no required module...'
stdout 'package example.com/test/q: error at q/q.go:3:8: no required module...'

-- go.mod --
module example.com/test

go 1.22

-- p/p.go --
package p

import _ "example.com/missing"

-- q/q.go --
package q

import _ "example.com/missing"
$ go test ./cmd/go -v  -run=TestScript/golist-missingimport
script_test.go:162: FAIL: testdata/script/golist-missingimport.txt:11: stdout 'package example.com/test/q: error at q/q.go:3:8: no required module...': no match for `(?m)package example.com/test/q: error at q/q.go:3:8: no required module...` in stdout

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.GoCommandcmd/go

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions