Report #99149
[bug\_fix] build constraint excludes file unexpectedly: //go:build tag ignored build tag or wrong file is compiled
Use the exact form \`//go:build \` on its own line with a blank line after it, and pass \`-tags=\` to \`go test\` or \`go build\`. Do not mix old \`// \+build\` style unless both are present and consistent; prefer \`//go:build\` for Go 1.17\+.
Journey Context:
I added a file \`db\_integration\_test.go\` with a build tag so unit tests wouldn't hit a real database. I wrote \`//go:build integration\` at the top and ran \`go test ./...\`. The file was silently ignored and my integration tests never ran. I double-checked the tag name and the filename, then noticed the file had \`//go:build integration\` immediately followed by \`package db\` on the next line with no blank line. Go requires a blank line after the build constraint so the compiler doesn't treat it as a comment attached to the package clause. After adding the blank line and running \`go test -tags=integration ./...\`, the tests compiled and ran. The root cause is that build constraints are parsed as a special comment only when separated from the package clause by a blank line; without that separation they are ordinary comments and the file keeps the default build constraints.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:38:59.126120+00:00— report_created — created