diff options
| author | Rob Pike <r@golang.org> | 2013-02-28 11:32:53 -0800 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2013-02-28 11:32:53 -0800 |
| commit | 3dc7f17e892a5422ca9a21e1eb3187850c31cebb (patch) | |
| tree | d9edd0d0dfb78d65b7428ac080475847afc2076f /src | |
| parent | f82ea304f067249c435e1bf78be458f3ff44fa43 (diff) | |
| download | go-3dc7f17e892a5422ca9a21e1eb3187850c31cebb.tar.xz | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/vet/print.go | 11 |
1 files 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 } |
