-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/go/analysis/passes/directive: spurious requirement for blank line between //go:debug
and package declaration
#66046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
//go:debug
and package declaration
//go:debug
and package declaration//go:debug
and package declaration
Not just tests, fails: https://go.dev/play/p/rM-aiRMn4rd //go:debug panicnil=1
package main
func main() {
panic(nil)
} vs passes: https://go.dev/play/p/BZY9qp1ilAI //go:debug panicnil=1
package main
func main() {
panic(nil)
} |
I suspect the directive analyzer handles // A +build comment is ignored after or adjoining the package declaration.
if group.End()+1 >= f.Package {
check.inHeader = false
} Assigning to @rsc to adjudicate the desired behavior. |
Change https://go.dev/cl/569360 mentions this issue: |
//go:debug comments are parsed by the same code that parses //go:build comments. So the vet warning seems consistent. That said, unless my testing is broken the parsing does currently permit the //go:build or //go:debug comment to appear as part of the package comment. The only requirement is that the comment appear before the |
@ianlancetaylor I don't interpret "(preceding the package statement)" on the documentation page on go:debug as requiring the comment having a newline between it and |
// +build comments need a blank line, because otherwise a package doc comment talking about the +build feature might Newer directives of the //tool:thing form do not need that blank line and do not have the wrapping problem. As part of the richer doc comment syntax, we updated gofmt and friends to move such directives to the end of doc comments and not to print them as documentation. Empirically, new-style directives, both //go:debug and //go:build, are recognized in package doc comments:
Since the standard tools recognize them in the package doc comment, x/tools/go/analysis should recognize them there too. But be sure not to start recognizing // +build in the package doc comment. It is possible that the code has always been wrong but it didn't matter because gofmt moves //go:build lines out of package doc comments into stanzas of their own. So it goes. |
Go version
go version go1.22.0 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Prompted by a question from Sean Sorrell in the #general channel in the Gophers Slack about using go:debug directives in test files, I wrote the following file called
main_test.go:
:According to the documentation, this should pass
go vet
.What did you see happen?
go vet .
returns:./main_test.go:1:1: //go:debug directive only valid before package declaration
What did you expect to see?
A clean
go vet
output.The text was updated successfully, but these errors were encountered: