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: false positive about unrecognized printf flag '0' #23598

Closed
marat-rkh opened this issue Jan 29, 2018 · 8 comments
Closed

cmd/vet: false positive about unrecognized printf flag '0' #23598

marat-rkh opened this issue Jan 29, 2018 · 8 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@marat-rkh
Copy link

marat-rkh commented Jan 29, 2018

Please answer these questions before submitting your issue. Thanks!

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

o1.9.3 darwin/amd64

What did you do?

Run go vet on the following file:

package main

import "fmt"

func main() {
	fmt.Printf("%08t", false)
}

What did you expect to see?

No errors are reported as '0' flag is valid for 't' verb. Program prints 000false, zeros are used for padding instead of spaces.

What did you see instead?

vet reports unrecognized printf flag for verb 't': '0'.

@robpike
Copy link
Contributor

robpike commented Jan 29, 2018

I see a couple of problems in there.

@mvdan
Copy link
Member

mvdan commented Jan 29, 2018

@robpike could you elaborate?

@marat-rkh
Copy link
Author

marat-rkh commented Jan 29, 2018

Hm... fmt documentation states that:
Flags are ignored by verbs that do not expect them. For example there is no alternate decimal format, so %#d and %d behave identically.
But go vet reports unrecognized flags as error. It this even correct? I understand that removing such redundancies from a source code is a good thing. But what about go vet executed before tests in Go 1.10?

@marat-rkh
Copy link
Author

Speaking about other problems of '0' flag processing by go vet.

fmt.Printf("%020p \n", &[]int{})
fmt.Printf("%020T \n", false)
fmt.Printf("%020U \n", 1234)

In all these cases '0' affects print result, but is reported by go vet as unrecognized.

@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Jan 29, 2018
@ianlancetaylor
Copy link
Contributor

This does not seem like unreasonable go vet behavior to me. The code is almost certainly mistaken even if fmt carries on as best it can.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.10, Go1.11 Jan 29, 2018
@ianlancetaylor ianlancetaylor added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jan 29, 2018
@dolmen
Copy link
Contributor

dolmen commented Jan 29, 2018

Here is an additional test case using fmt.Formatter to let you decide what should be the bahaviour of "go vet":

package main

import (
	"fmt"
)

type t struct{}

func (_ t) Format(f fmt.State, c rune) {
	if f.Flag('0') {
		f.Write([]byte("GA"))
	} else {
		f.Write([]byte("BU"))
	}
}

func main() {
	fmt.Printf("%0s\n", t{})
}

@robpike
Copy link
Contributor

robpike commented Jan 30, 2018

https://go-review.googlesource.com/c/go/+/90695 was supposed to mention this issue but got the issue number wrong.

@spf13 spf13 added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 26, 2018
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 26, 2018
@ianlancetaylor
Copy link
Contributor

Fixed by https://golang.org/cl/90695.

@golang golang locked and limited conversation to collaborators Mar 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants