cmd/go: Builds using go1.16.x report an ambiguous error when an imported dependency contains '//go:build' but not '// +build' #51436
Labels
GoCommand
cmd/go
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No. Both go1.17 and go1.18rc1 work correctly.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Several of our internal modules at work have recently started failing to build with an error that says nothing more than
//go:build comment without // +build comment
. We were able to determine that the error only happens for things that are still on Go 1.16.x and upgrading them to 1.17 made the error go away.Further digging revealed that the actual problem was within the bitbucket.org/bertimus9/systemstat module, which removed
// +build
directive comments with this commit, purportedly to "update to play nice with go 1.17".The snippet below is a minimal reproducible example (included here because go.dev/play doesn't seem to have an option to use go1.16.x):
Attempting to build the code above generates the following error when using Go 1.16.x:
The behavior is correct according to this proposal, but the error message gives no indication that the missing
// +build
directive inside of a dependency. Instead it shows the source/line information for the import of the "bad" package.What did you expect to see?
An error with the source/line information pointing to the dependency's code, where the problem actually exists.
What did you see instead?
An error with the source/line information pointing at my own code with no explanation that the issue actually exists elsewhere.
The text was updated successfully, but these errors were encountered: