]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: continue past first error
authorRob Pike <r@golang.org>
Wed, 27 Feb 2013 23:43:33 +0000 (15:43 -0800)
committerRob Pike <r@golang.org>
Wed, 27 Feb 2013 23:43:33 +0000 (15:43 -0800)
Also delete bogus tests for f.pkg (does the file have a package) since all
files have a package attached. The tests for pkg.types and pkg.values
suffice.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7418043

src/cmd/vet/main.go
src/cmd/vet/print.go
src/cmd/vet/taglit.go

index 85eab788e9644a84198bc348732353b029d9ca3a..8d575e20b253de979c5b802cc269ffffa09f9fc0 100644 (file)
@@ -160,6 +160,7 @@ func doPackageDir(directory string) {
                return
        }
        var names []string
+       names = append(names, pkg.GoFiles...)
        names = append(names, pkg.CgoFiles...)
        names = append(names, pkg.TestGoFiles...) // These are also in the "foo" package.
        prefixDirectory(directory, names)
@@ -209,8 +210,11 @@ func doPackage(names []string) {
                        pkg.values[x] = val
                }
        }
+       // By providing the Context with our own error function, it will continue
+       // past the first error. There is no need for that function to do anything.
        context := types.Context{
-               Expr: exprFn,
+               Expr:  exprFn,
+               Error: func(error) {},
        }
        // Type check the package.
        _, err := context.Check(fs, astFiles)
index 5b012027101a5c8c84fd42d098b46d91fa79ef7a..487ccb4149f577856d00368c8de7cb07ce430909 100644 (file)
@@ -276,9 +276,6 @@ func (f *File) checkPrintfArg(call *ast.CallExpr, verb rune, flags []byte, argNu
                                        return
                                }
                        }
-                       if f.pkg == nil { // Nothing more to do.
-                               return
-                       }
                        // Verb is good. If nargs>1, we have something like %.*s and all but the final
                        // arg must be integer.
                        for i := 0; i < nargs-1; i++ {
@@ -373,13 +370,13 @@ func (f *File) checkPrint(call *ast.CallExpr, name string, firstArg int) {
                // If we have a call to a method called Error that satisfies the Error interface,
                // then it's ok. Otherwise it's something like (*T).Error from the testing package
                // and we need to check it.
-               if name == "Error" && f.pkg != nil && f.isErrorMethodCall(call) {
+               if name == "Error" && f.isErrorMethodCall(call) {
                        return
                }
                // If it's an Error call now, it's probably for printing errors.
                if !isLn {
                        // Check the signature to be sure: there are niladic functions called "error".
-                       if f.pkg == nil || firstArg != 0 || f.numArgsInSignature(call) != firstArg {
+                       if firstArg != 0 || f.numArgsInSignature(call) != firstArg {
                                f.Badf(call.Pos(), "no args in %s call", name)
                        }
                }
@@ -403,7 +400,7 @@ func (f *File) checkPrint(call *ast.CallExpr, name string, firstArg int) {
 }
 
 // numArgsInSignature tells how many formal arguments the function type
-// being called has. Assumes type checking is on (f.pkg != nil).
+// being called has.
 func (f *File) numArgsInSignature(call *ast.CallExpr) int {
        // Check the type of the function or method declaration
        typ := f.pkg.types[call.Fun]
@@ -420,8 +417,7 @@ func (f *File) numArgsInSignature(call *ast.CallExpr) int {
 
 // isErrorMethodCall reports whether the call is of a method with signature
 //     func Error() string
-// where "string" is the universe's string type. We know the method is called "Error"
-// and f.pkg is set.
+// where "string" is the universe's string type. We know the method is called "Error".
 func (f *File) isErrorMethodCall(call *ast.CallExpr) bool {
        // Is it a selector expression? Otherwise it's a function call, not a method call.
        sel, ok := call.Fun.(*ast.SelectorExpr)
index 2ae0b2ad445793fb1f427494743a2e07735a7b31..0324e37b06106f013b249b7e1e95ac3543ae1d42 100644 (file)
@@ -22,20 +22,18 @@ func (f *File) checkUntaggedLiteral(c *ast.CompositeLit) {
                return
        }
 
-       // Check that the CompositeLit's type is a slice or array (which need no tag), if possible.
-       if f.pkg != nil {
-               typ := f.pkg.types[c]
-               if typ != nil {
-                       // If it's a named type, pull out the underlying type.
-                       if namedType, ok := typ.(*types.NamedType); ok {
-                               typ = namedType.Underlying
-                       }
-                       switch typ.(type) {
-                       case *types.Slice:
-                               return
-                       case *types.Array:
-                               return
-                       }
+       // Check that the CompositeLit's type is a slice or array (which needs no tag), if possible.
+       typ := f.pkg.types[c]
+       if typ != nil {
+               // If it's a named type, pull out the underlying type.
+               if namedType, ok := typ.(*types.NamedType); ok {
+                       typ = namedType.Underlying
+               }
+               switch typ.(type) {
+               case *types.Slice:
+                       return
+               case *types.Array:
+                       return
                }
        }
 
@@ -69,8 +67,8 @@ func (f *File) checkUntaggedLiteral(c *ast.CompositeLit) {
                f.Warnf(c.Pos(), "unresolvable package for %s.%s literal", pkg.Name, s.Sel.Name)
                return
        }
-       typ := path + "." + s.Sel.Name
-       if *compositeWhiteList && untaggedLiteralWhitelist[typ] {
+       typeName := path + "." + s.Sel.Name
+       if *compositeWhiteList && untaggedLiteralWhitelist[typeName] {
                return
        }