Skip to content

go build has unexpected behavior #68042

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

Closed
FGYFFFF opened this issue Jun 18, 2024 · 2 comments
Closed

go build has unexpected behavior #68042

FGYFFFF opened this issue Jun 18, 2024 · 2 comments

Comments

@FGYFFFF
Copy link

FGYFFFF commented Jun 18, 2024

Go version

go version go1.21.9 darwin/amd64

Output of go env in your module/workspace:

$ go env
GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOOS='darwin'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.google.cn'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.9'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'

What did you do?

i write a build tag for my code, like below:

.
├── a.go
├── a_a.go
├── a_test.go
└── go.mod

a.go
// note: i write wrong format for // +build

//go:build rgoinjec
// +build rgoinject
package test2

import "fmt"

func A() {
	fmt.Println("a")
}

a_a.go

package test2

import "fmt"

func A() {
	fmt.Println("a")
}

a_test.go

package test2

import "testing"

func TestA(t *testing.T) {
	A()
}
  • go build ./... build success
  • go test ./... test failed

What did you see happen?

I write the wrong format build tag for a.go. It will compile successfully by go build ./..., but it will fail by go test ./...
image

What did you expect to see?

I think go test & go build both to report the wrong format for my code.

@ianlancetaylor
Copy link
Contributor

The error is being reported by go vet. Running go test automatically runs go vet. Running go build does not. This is working as documented and expected, so closing. Thanks for reporting it.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants