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/vet: printf analyzer fails with generics #70572

Closed
larhun opened this issue Nov 26, 2024 · 6 comments
Closed

cmd/vet: printf analyzer fails with generics #70572

larhun opened this issue Nov 26, 2024 · 6 comments
Assignees
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@larhun
Copy link

larhun commented Nov 26, 2024

Go version

go version go1.22.3 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\***\AppData\Local\go-build
set GOENV=C:\Users\***\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\***\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\***\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.3
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=***
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\***\AppData\Local\Temp\go-build193180697=/tmp/go-build -gno-record-gcc-switches

What did you do?

Run this code in Go Playground (https://go.dev/play/p/Bop_vKP8EM0) or edit with vscode.

package main

import (
	"fmt"
)

type A struct{}

func (v A) Printf(format string, values ...any) {
	fmt.Printf(format, values...)
}

type B[T any] struct{}

func (v B[T]) Printf(format string, values ...any) {
	fmt.Printf(format, values...)
}

func main() {
	var a A
	var b B[bool]
	a.Printf("x", 1)
	b.Printf("x", 1)
}

What did you see happen?

Go vet failed on line 22 with the following log and line 22 is marked as failed in vscode.

# [play]
./prog.go:22:10: (play.A).Printf call has arguments but no formatting directives

Go vet failed.

x%!(EXTRA int=1)x%!(EXTRA int=1)
Program exited.

What did you expect to see?

Go vet failed on lines 22 and 23 with the following log and lines 22 and 23 are marked as failed in vscode.

# [play]
./prog.go:22:10: (play.A).Printf call has arguments but no formatting directives
./prog.go:23:10: (play.B).Printf call has arguments but no formatting directives

Go vet failed.

x%!(EXTRA int=1)x%!(EXTRA int=1)
Program exited.
@GoVeronicaGo
Copy link

cc: @matloob

@GoVeronicaGo GoVeronicaGo added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 26, 2024
@adonovan adonovan added the Analysis Issues related to static analysis (vet, x/tools/go/analysis) label Nov 26, 2024
@adonovan
Copy link
Member

Thanks for the helpful report; I agree that this is a bug.

@adonovan adonovan self-assigned this Nov 26, 2024
@adonovan
Copy link
Member

https://go.dev/cl/631955 fixes the bug in x/tools; but we would need to re-vendor or cherrypick it into GOROOT for cmd/vet in go1.24.

@dmitshur

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/631955 mentions this issue: go/analysis/passes/printf: add missing call to Func.Origin

@adonovan adonovan added this to the Go1.24 milestone Nov 26, 2024
@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 26, 2024
@dmitshur
Copy link
Contributor

@adonovan Ack. That'll happen before RC 1 via another round in #36905, or it can be an individual CL sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Analysis Issues related to static analysis (vet, x/tools/go/analysis) NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants