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 check misses strings that are + together #30436

Open
imirkin opened this issue Feb 27, 2019 · 2 comments

Comments

@imirkin
Copy link

@imirkin imirkin commented Feb 27, 2019

With this example put into https://play.golang.org/ (and go1.11), there is no warning. Joining the two strings into 1 results in a warning.

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello, playground %d" + "", 5)
}

Some people split long strings, which is where I encountered it.

@bcmills bcmills changed the title vet: printf check misses strings that are + together cmd/vet: printf check misses strings that are + together Feb 27, 2019
@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Feb 27, 2019

@alandonovan

This comment has been minimized.

Copy link
Contributor

@alandonovan alandonovan commented Feb 27, 2019

Thanks, this is indeed a bug. The checkPrint function in golang.org/x/tools/go/analysis/passes/printf/printf.go looks for ast.BasicLit, which is a relic of the older implementation which could not assume well-typed syntax trees. Now it's better to look for expressions that are string constants, independent of their syntax, as we do when checking Printf (not Println as in your example).

@ALTree ALTree added this to the Unplanned milestone Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.