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/types: error diagnostics reported by go/types contain %!v(MISSING) #60500

Closed
myitcv opened this issue May 30, 2023 · 5 comments
Closed

go/types: error diagnostics reported by go/types contain %!v(MISSING) #60500

myitcv opened this issue May 30, 2023 · 5 comments
Assignees
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@myitcv
Copy link
Member

myitcv commented May 30, 2023

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

$ go version
go version go1.20.4 linux/arm64
$ go list -m golang.org/x/tools
golang.org/x/tools v0.9.2-0.20230526183654-5974258e689a
$ go list -m golang.org/x/tools/gopls
golang.org/x/tools/gopls v0.0.0-20230526183654-5974258e689a

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="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOENV="/home/myitcv/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/myitcv/gostuff/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/myitcv/gos"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.20.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/myitcv/gostuff/src/github.com/myitcv/playground/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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1568132059=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Load the following file with a gopls-enabled editor:

package main

func main() {
	log("This is a test %v", 5)
}

func log(enabled bool, format string, args ...any) {
	log.Printf(format, args...)
}

What did you expect to see?

The following diagnostics (showing the vim-rendered version):

main.go|4 col 6| cannot use "This is a test %v" (untyped string constant) as bool value in argument to log
main.go|4 col 27| cannot use 5 (untyped int constant) as string value in argument to log
main.go|8 col 6| log.Printf undefined (type func(enabled bool, format string, args ...any) has no field or method Printf)

What did you see instead?

main.go|4 col 6| cannot use "This is a test %!v(MISSING)" (untyped string constant) as bool value in argument to log
main.go|4 col 27| cannot use 5 (untyped int constant) as string value in argument to log
main.go|8 col 6| log.Printf undefined (type func(enabled bool, format string, args ...any) has no field or method Printf)

Note the presence of %!v(MISSING) in the first line.

Log files:


cc @findleyr

@myitcv myitcv added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. labels May 30, 2023
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 30, 2023
@gopherbot gopherbot added this to the Unreleased milestone May 30, 2023
@findleyr findleyr changed the title x/tools/gopls: error diagnostics reported by gopls contain %!v(MISSING) go/types: error diagnostics reported by go/types contain %!v(MISSING) May 30, 2023
@findleyr findleyr modified the milestones: Unreleased, Go1.21 May 30, 2023
@findleyr
Copy link
Contributor

Thank you for the report.

This is reproducible with go/types alone (simply copy the example above into src/go/types/testdata/manual.go.

We should not be passing user content as format strings, therefore this is a release blocker.

CC @griesemer

@griesemer griesemer self-assigned this May 30, 2023
@griesemer
Copy link
Contributor

griesemer commented May 30, 2023

Does not happen with types2. Fix forthcoming.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/499275 mentions this issue: go/types: don't use user string as format string

@adonovan
Copy link
Member

adonovan commented May 31, 2023

Perhaps the printf vet checker should be able to catch problems like this: a variable format string is passed to a printf wrapper, followed by no other arguments. I can't see how that would ever be useful.

See #60529.

@griesemer
Copy link
Contributor

griesemer commented May 31, 2023 via email

@golang golang locked and limited conversation to collaborators May 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants