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

go vet incorrectly recognizes format verb in string #38131

Closed
skaldesh opened this issue Mar 28, 2020 · 3 comments
Closed

go vet incorrectly recognizes format verb in string #38131

skaldesh opened this issue Mar 28, 2020 · 3 comments

Comments

@skaldesh
Copy link

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

$ go version
go version go1.14.1 linux/amd64

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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/skaldesh/.cache/go-build"
GOENV="/home/skaldesh/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOOS="linux"
GOPATH="/home/skaldesh/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build572355618=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I wrote a function that executes either fmt.Printf or fmt.Print, based on its arguments.
I am using it to generate go code

Sample: https://play.golang.org/p/Pb1JwPOmDLd

What did you expect to see?

No go vet error, as it lets my tests fail.

What did you see instead?

go vet error: write format %s reads arg #1, but call has 0 args

Additional info

It may be related to this old issue?

@ianlancetaylor
Copy link
Contributor

I think it's asking quite a lot for vet to be able to disentangle this code. Normally a string is either a format or it isn't. It's a reasonable assumption for vet to make. In your case a string is sometimes a format string and sometimes isn't. If you want to use vet on your code, either use "%s" with a single argument, or use a separate function when you don't want to do formatting.

@skaldesh
Copy link
Author

My intention was not to demand that go vet supports this. I was more surprised that I can not write this code and have my tests work at the same time...

@ianlancetaylor
Copy link
Contributor

go test runs go vet by default. You can this with the -vet=off flag.

@golang golang locked and limited conversation to collaborators Mar 28, 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