Skip to content
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

No use of functions that belong to files marked with //go:build tag is recognized #65113

Closed
rose-giant opened this issue Jan 16, 2024 · 2 comments

Comments

@rose-giant
Copy link

Go version

go version 1.21

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/razie/.cache/go-build'
GOENV='/home/razie/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/razie/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/razie/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/razie/Desktop/xmsa/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build443146793=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I have two files marked with the tags below, each of which contains a function and either the first or the second is supposed to be compiled:

//go:build !A && B
// +build !A,B

func InitM() (m.M) {
b := & r.SampleStruct{}
return b
}

//go:build A && !B
// +build A,!B

func InitM() (m.M) {
a := & r.SampleStruct{}
return a
}

What did you see happen?

The problem is that when I call the function InitM in a package, neither of the function nor its return value is recognized
for instance in the code below, the function is called and its return value is stored in the variable a
a := InitM()

Assume that there exists a function called Run() in the class to which a belongs. If the function is called on a as below, the use of Run() is not recognized in the program since a is not recognized as well
a.Run()

What did you expect to see?

I know what distinguishes this feature is that it works and is recognized during the compilation of the program but the fact that no use of the functions applied is recognized is sort of annoying. During a code review, I was accused to define a function that was never used in the program because the guy reviewing, right clicked on the function Run() and after hitting "Go to references" did not find any

@thediveo
Copy link
Contributor

I can only guess here, as you don't give necessary information about whether you have defined any build tags at all and how exactly the go toolchain is used in some review process. Maybe this post #29202 (comment) about gopls and build tags might help? This looks like a question for a forum like golang-nuts.

@seankhliao
Copy link
Member

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2024
@golang golang locked and limited conversation to collaborators Jan 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants