1
0
mirror of https://github.com/golang/go synced 2024-11-13 18:50:24 -07:00

cmd/vet: continue past first error

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
This commit is contained in:
Rob Pike 2013-02-27 15:43:33 -08:00
parent 76e4a03352
commit 9e19337de9
3 changed files with 23 additions and 25 deletions

View File

@ -160,6 +160,7 @@ func doPackageDir(directory string) {
return return
} }
var names []string var names []string
names = append(names, pkg.GoFiles...)
names = append(names, pkg.CgoFiles...) names = append(names, pkg.CgoFiles...)
names = append(names, pkg.TestGoFiles...) // These are also in the "foo" package. names = append(names, pkg.TestGoFiles...) // These are also in the "foo" package.
prefixDirectory(directory, names) prefixDirectory(directory, names)
@ -209,8 +210,11 @@ func doPackage(names []string) {
pkg.values[x] = val 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{ context := types.Context{
Expr: exprFn, Expr: exprFn,
Error: func(error) {},
} }
// Type check the package. // Type check the package.
_, err := context.Check(fs, astFiles) _, err := context.Check(fs, astFiles)

View File

@ -276,9 +276,6 @@ func (f *File) checkPrintfArg(call *ast.CallExpr, verb rune, flags []byte, argNu
return 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 // Verb is good. If nargs>1, we have something like %.*s and all but the final
// arg must be integer. // arg must be integer.
for i := 0; i < nargs-1; i++ { 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, // 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 // then it's ok. Otherwise it's something like (*T).Error from the testing package
// and we need to check it. // and we need to check it.
if name == "Error" && f.pkg != nil && f.isErrorMethodCall(call) { if name == "Error" && f.isErrorMethodCall(call) {
return return
} }
// If it's an Error call now, it's probably for printing errors. // If it's an Error call now, it's probably for printing errors.
if !isLn { if !isLn {
// Check the signature to be sure: there are niladic functions called "error". // 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) 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 // 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 { func (f *File) numArgsInSignature(call *ast.CallExpr) int {
// Check the type of the function or method declaration // Check the type of the function or method declaration
typ := f.pkg.types[call.Fun] 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 // isErrorMethodCall reports whether the call is of a method with signature
// func Error() string // func Error() string
// where "string" is the universe's string type. We know the method is called "Error" // where "string" is the universe's string type. We know the method is called "Error".
// and f.pkg is set.
func (f *File) isErrorMethodCall(call *ast.CallExpr) bool { func (f *File) isErrorMethodCall(call *ast.CallExpr) bool {
// Is it a selector expression? Otherwise it's a function call, not a method call. // Is it a selector expression? Otherwise it's a function call, not a method call.
sel, ok := call.Fun.(*ast.SelectorExpr) sel, ok := call.Fun.(*ast.SelectorExpr)

View File

@ -22,8 +22,7 @@ func (f *File) checkUntaggedLiteral(c *ast.CompositeLit) {
return return
} }
// Check that the CompositeLit's type is a slice or array (which need no tag), if possible. // Check that the CompositeLit's type is a slice or array (which needs no tag), if possible.
if f.pkg != nil {
typ := f.pkg.types[c] typ := f.pkg.types[c]
if typ != nil { if typ != nil {
// If it's a named type, pull out the underlying type. // If it's a named type, pull out the underlying type.
@ -37,7 +36,6 @@ func (f *File) checkUntaggedLiteral(c *ast.CompositeLit) {
return return
} }
} }
}
// It's a struct, or we can't tell it's not a struct because we don't have types. // It's a struct, or we can't tell it's not a struct because we don't have types.
@ -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) f.Warnf(c.Pos(), "unresolvable package for %s.%s literal", pkg.Name, s.Sel.Name)
return return
} }
typ := path + "." + s.Sel.Name typeName := path + "." + s.Sel.Name
if *compositeWhiteList && untaggedLiteralWhitelist[typ] { if *compositeWhiteList && untaggedLiteralWhitelist[typeName] {
return return
} }