mirror of
https://github.com/golang/go
synced 2024-11-12 08:50:22 -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:
parent
76e4a03352
commit
9e19337de9
@ -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,
|
||||
Error: func(error) {},
|
||||
}
|
||||
// Type check the package.
|
||||
_, err := context.Check(fs, astFiles)
|
||||
|
@ -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)
|
||||
|
@ -22,8 +22,7 @@ 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 {
|
||||
// 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.
|
||||
@ -37,7 +36,6 @@ func (f *File) checkUntaggedLiteral(c *ast.CompositeLit) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
return
|
||||
}
|
||||
typ := path + "." + s.Sel.Name
|
||||
if *compositeWhiteList && untaggedLiteralWhitelist[typ] {
|
||||
typeName := path + "." + s.Sel.Name
|
||||
if *compositeWhiteList && untaggedLiteralWhitelist[typeName] {
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user