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 positives with new fmt verbs %x/%X for floating-point and complex numbers #34993

Closed
cespare opened this issue Oct 18, 2019 · 5 comments
Labels
Milestone

Comments

@cespare
Copy link
Contributor

@cespare cespare commented Oct 18, 2019

I don't think vet has been updated for the new %x and %X verbs for floating-point and complex numbers.

I checked with Go 1.13 and tip. Here's a demo:

https://play.golang.org/p/-cexq-umzUo

Code:

package main

import "fmt"

func main() {
	fmt.Printf("%x\n", 1.234)
	fmt.Printf("%x\n", 1.2+3i)
	fmt.Printf("%X\n", 1.234)
	fmt.Printf("%X\n", 1.2+3i)
}

Output:

./prog.go:6:2: Printf format %x has arg 1.234 of wrong type float64
./prog.go:7:2: Printf format %x has arg 1.2 + 3i of wrong type complex128
./prog.go:8:2: Printf format %X has arg 1.234 of wrong type float64
./prog.go:9:2: Printf format %X has arg 1.2 + 3i of wrong type complex128
Go vet exited.

0x1.3be76c8b43958p+00
(0x1.3333333333333p+00+0x1.8p+01i)
0X1.3BE76C8B43958P+00
(0X1.3333333333333P+00+0X1.8P+01i)

Program exited.
@cespare cespare added this to the Go1.14 milestone Oct 18, 2019
@julieqiu
Copy link
Contributor

@julieqiu julieqiu commented Oct 18, 2019

@cespare
Copy link
Contributor Author

@cespare cespare commented Oct 18, 2019

I believe the fix is trivial. I'll send a CL for x/tools and then re-vendor the copy in src/cmd after that's merged.

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 18, 2019

Change https://golang.org/cl/202041 mentions this issue: go/analysis/passes/printf: allow %x/%X for float/complex types

gopherbot pushed a commit to golang/tools that referenced this issue Oct 18, 2019
These verbs are supported as of Go 1.13.

Updates golang/go#34993

Change-Id: Ib7892e45b51073e3771bebb652a8fe3a1c6ae3c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202041
Run-TryBot: Caleb Spare <cespare@gmail.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 18, 2019

Change https://golang.org/cl/202083 mentions this issue: cmd/vet: re-vendor x/tools upstream for printf verb fix

@gopherbot gopherbot closed this in 72275c0 Oct 19, 2019
@gopherbot
Copy link

@gopherbot gopherbot commented Jun 15, 2020

Change https://golang.org/cl/237942 mentions this issue: [release-branch.go1.13] go/analysis/passes/printf: allow %x/%X for float/complex types

gopherbot pushed a commit to golang/tools that referenced this issue Jun 15, 2020
…oat/complex types

These verbs are supported as of Go 1.13.

Updates golang/go#34993.
For golang/go#39287.

Change-Id: Ib7892e45b51073e3771bebb652a8fe3a1c6ae3c6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202041
Run-TryBot: Caleb Spare <cespare@gmail.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
(cherry picked from commit 04252ec)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237942
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants