From 3dc7f17e892a5422ca9a21e1eb3187850c31cebb Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Thu, 28 Feb 2013 11:32:53 -0800 Subject: [PATCH] cmd/vet: %b is a valid floating-point format. Also add a report about "invalid type" from gotype, if -v is set. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/7420045 --- src/cmd/vet/print.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cmd/vet/print.go b/src/cmd/vet/print.go index 487ccb4149..70ece02bf5 100644 --- a/src/cmd/vet/print.go +++ b/src/cmd/vet/print.go @@ -243,7 +243,7 @@ var printVerbs = []printVerb{ // '+' is required sign for numbers, Go format for %v. // '#' is alternate format for several verbs. // ' ' is spacer for numbers - {'b', numFlag, argInt}, + {'b', numFlag, argInt | argFloat}, {'c', "-", argRune | argInt}, {'d', numFlag, argInt}, {'e', numFlag, argFloat}, @@ -280,7 +280,7 @@ func (f *File) checkPrintfArg(call *ast.CallExpr, verb rune, flags []byte, argNu // arg must be integer. for i := 0; i < nargs-1; i++ { if !f.matchArgType(argInt, call.Args[argNum+i]) { - f.Badf(call.Pos(), "arg for * in printf format not of type int") + f.Badf(call.Pos(), "arg %s for * in printf format not of type int", call.Args[argNum+i]) } } for _, v := range printVerbs { @@ -291,7 +291,7 @@ func (f *File) checkPrintfArg(call *ast.CallExpr, verb rune, flags []byte, argNu if typ := f.pkg.types[arg]; typ != nil { typeString = typ.String() } - f.Badf(call.Pos(), "arg for printf verb %%%c of wrong type: %s", verb, typeString) + f.Badf(call.Pos(), "arg %s for printf verb %%%c of wrong type: %s", arg, verb, typeString) } break } @@ -346,6 +346,11 @@ func (f *File) matchArgType(t printfArgType, arg ast.Expr) bool { return t&argString != 0 case types.UntypedNil: return t&argPointer != 0 // TODO? + case types.Invalid: + if *verbose { + f.Warnf(arg.Pos(), "printf argument %v has invalid or unknown type", arg) + } + return true // Probably a type check problem. } return false } -- 2.48.1