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

cmd/go: build tags not working if preceeded with /* */ comments #43286

Closed
AlexRouSg opened this issue Dec 20, 2020 · 4 comments
Closed

cmd/go: build tags not working if preceeded with /* */ comments #43286

AlexRouSg opened this issue Dec 20, 2020 · 4 comments

Comments

@AlexRouSg
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
1.15.6
1.14.13
1.16beta1

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=off
set GOARCH=amd64
set GOBIN=
set GOCACHE=%USERPROFILE%\AppData\Local\go-build
set GOENV=%USERPROFILE%\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=%USERPROFILE%\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=%USERPROFILE%\go;
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\alexr\AppData\Local\Temp\go-build874774134=/tmp/go-build -gno-record-gcc-switches

What did you do?

go run .
-- main.go --

/*
	test
*/

//+build !foo

package main

import "fmt"

func main() {
	fmt.Println("!foo")
}

-- main2.go --

/*
	test
*/ 

//+build foo

package main

import "fmt"

func main() {
	fmt.Println("foo")
}

What did you expect to see?

Output: !foo
This works if instead of /* */ comments I used // comments in the same places

What did you see instead?

.\main2.go:13:6: main redeclared in this block
        previous declaration at .\main.go:13:6
@davecheney
Copy link
Contributor

davecheney commented Dec 20, 2020

This is working as intended, go vet will highlight the error that the build tag must be the first line of the file and there must be a space between // and +build

@AlexRouSg
Copy link
Contributor Author

AlexRouSg commented Dec 20, 2020

@davecheney then why does this work?

// test

//+build foo

package main

import "fmt"

func main() {
	fmt.Println("foo")
}

Also vet only says vet.exe: .\main2.go:13:6: main redeclared in this block

@davecheney
Copy link
Contributor

I don’t make the rules, I’m just telling you what they are. If vet is happy with this input then maybe that’s a bug.

@davecheney
Copy link
Contributor

I'm sorry, my previous comment was not productive.

I'm not sure why vet isn't flagging your incorrect build tag, but I'm guessing it is because the tag is both in the wrong place, it isn't the first line of the file, and there is no space between the // and +build. There is a newline following the build tag, which is necessary, but my guess is, given there is an unlimited number of constructions which are not valid build tags, vet just gave up. I don't know if there is a vet analyser for //+build anywhere in the file, that seems like something that would be useful.

@golang golang locked and limited conversation to collaborators Dec 20, 2021
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

3 participants