]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: %b is a valid floating-point format.
authorRob Pike <r@golang.org>
Thu, 28 Feb 2013 19:32:53 +0000 (11:32 -0800)
committerRob Pike <r@golang.org>
Thu, 28 Feb 2013 19:32:53 +0000 (11:32 -0800)
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

index 487ccb4149f577856d00368c8de7cb07ce430909..70ece02bf532151d2e3df32be705394c73f8b56a 100644 (file)
@@ -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
 }