Skip to content

cmd/vet: false positives with new fmt verbs %x/%X for floating-point and complex numbers #34993

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

Closed
cespare opened this issue Oct 18, 2019 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@cespare
Copy link
Contributor

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
Member

/cc @alandonovan @josharian @mvdan

@julieqiu julieqiu added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 18, 2019
@cespare
Copy link
Contributor Author

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
Contributor

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 <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
@gopherbot
Copy link
Contributor

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

@gopherbot
Copy link
Contributor

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 <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
(cherry picked from commit 04252ec)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/237942
Run-TryBot: Dmitri Shuralyov <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
@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 Jun 15, 2020
@golang golang locked and limited conversation to collaborators Jun 15, 2021
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

4 participants