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: vet printf attempts to validate flags on custom formatters #22608

Closed
soniakeys opened this issue Nov 7, 2017 · 4 comments
Closed

cmd/go: vet printf attempts to validate flags on custom formatters #22608

soniakeys opened this issue Nov 7, 2017 · 4 comments
Milestone

Comments

@soniakeys
Copy link

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

go version devel +36323e4 Tue Nov 7 01:50:16 2017 +0000 linux/amd64

Does this issue reproduce with the latest release?

In go vet 1.9, yes, but now it is an issue with the new go test on tip.

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

GOARCH="amd64"
GOOS="linux"
...

What did you do?

custom_test.go:

package custom

import (
    "fmt"
    "testing"
)

type custom int

func (custom) Format(fmt.State, rune) {}

func Test(t *testing.T) {
    fmt.Printf("%z", custom(0))
    fmt.Printf("%#z", custom(0))
    fmt.Printf("%#s", custom(0)) // unrecognized flag
}

What did you expect to see?

$ go test
PASS

What did you see instead?

$ go test
# custom
./custom_test.go:15: Printf format %#s has unrecognized flag #

Some code in okPrintfArg, in cmd/vet/print.go, handles custom formatters already. This case might be handled similarly to the way it passes unrecognized verbs for custom formatters.

@ChrisHines
Copy link
Contributor

This issue causes CI builds against tip to break for my package github.com/go-stack/stack, which supports the %#s format strings (as documented here: https://godoc.org/github.com/go-stack/stack#Call.Format).

@gopherbot
Copy link

Change https://golang.org/cl/77230 mentions this issue: cmd/vet: ignore unrecognized flags for fmt.Formatter

@ChrisHines
Copy link
Contributor

In my opinion this issue makes the printf checks not 100% reliable for purposes of #18085.

@rsc rsc added this to the Go1.10 milestone Nov 13, 2017
@rsc
Copy link
Contributor

rsc commented Nov 13, 2017

This report is great, thanks. We know we need to cut the printf check back just a bit; concrete details are very helpful.

@golang golang locked and limited conversation to collaborators Nov 13, 2018
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