Commit 8cf6e75e authored by Rob Pike's avatar Rob Pike

cmd/vet: change some warnings to errors for consistency.

Fixes #4980.

R=golang-dev, rsc, dsymonds
CC=golang-dev
https://golang.org/cl/7479044
parent b3915112
...@@ -9,6 +9,12 @@ calls whose arguments do not align with the format string. Vet uses heuristics ...@@ -9,6 +9,12 @@ calls whose arguments do not align with the format string. Vet uses heuristics
that do not guarantee all reports are genuine problems, but it can find errors that do not guarantee all reports are genuine problems, but it can find errors
not caught by the compilers. not caught by the compilers.
Its exit code is 2 for erroneous invocation of the tool, 1 if a
problem was reported, and 0 otherwise. Note that the tool does not
check every possible problem and depends on unreliable heuristics
so it should be used as guidance only, not as a firm indicator of
program correctness.
By default all checks are performed, but if explicit flags are provided, only By default all checks are performed, but if explicit flags are provided, only
those identified by the flags are performed. those identified by the flags are performed.
......
...@@ -186,17 +186,21 @@ func doPackage(names []string) { ...@@ -186,17 +186,21 @@ func doPackage(names []string) {
for _, name := range names { for _, name := range names {
f, err := os.Open(name) f, err := os.Open(name)
if err != nil { if err != nil {
errorf("%s: %s", name, err) // Warn but continue to next package.
warnf("%s: %s", name, err)
return
} }
defer f.Close() defer f.Close()
data, err := ioutil.ReadAll(f) data, err := ioutil.ReadAll(f)
if err != nil { if err != nil {
errorf("%s: %s", name, err) warnf("%s: %s", name, err)
return
} }
checkBuildTag(name, data) checkBuildTag(name, data)
parsedFile, err := parser.ParseFile(fs, name, bytes.NewReader(data), 0) parsedFile, err := parser.ParseFile(fs, name, bytes.NewReader(data), 0)
if err != nil { if err != nil {
errorf("%s: %s", name, err) warnf("%s: %s", name, err)
return
} }
files = append(files, &File{fset: fs, name: name, file: parsedFile}) files = append(files, &File{fset: fs, name: name, file: parsedFile})
astFiles = append(astFiles, parsedFile) astFiles = append(astFiles, parsedFile)
...@@ -229,7 +233,8 @@ func doPackage(names []string) { ...@@ -229,7 +233,8 @@ func doPackage(names []string) {
func visit(path string, f os.FileInfo, err error) error { func visit(path string, f os.FileInfo, err error) error {
if err != nil { if err != nil {
errorf("walk error: %s", err) warnf("walk error: %s", err)
return err
} }
// One package per directory. Ignore the files themselves. // One package per directory. Ignore the files themselves.
if !f.IsDir() { if !f.IsDir() {
...@@ -239,7 +244,7 @@ func visit(path string, f os.FileInfo, err error) error { ...@@ -239,7 +244,7 @@ func visit(path string, f os.FileInfo, err error) error {
return nil return nil
} }
// walkDir recursively walks the tree looking for .go files. // walkDir recursively walks the tree looking for Go packages.
func walkDir(root string) { func walkDir(root string) {
filepath.Walk(root, visit) filepath.Walk(root, visit)
} }
......
...@@ -93,7 +93,7 @@ func (f *File) checkCanonicalMethod(id *ast.Ident, t *ast.FuncType) { ...@@ -93,7 +93,7 @@ func (f *File) checkCanonicalMethod(id *ast.Ident, t *ast.FuncType) {
actual = strings.TrimPrefix(actual, "func") actual = strings.TrimPrefix(actual, "func")
actual = id.Name + actual actual = id.Name + actual
f.Warnf(id.Pos(), "method %s should have signature %s", actual, expectFmt) f.Badf(id.Pos(), "method %s should have signature %s", actual, expectFmt)
} }
} }
......
...@@ -366,7 +366,7 @@ func (f *File) checkPrint(call *ast.CallExpr, name string, firstArg int) { ...@@ -366,7 +366,7 @@ func (f *File) checkPrint(call *ast.CallExpr, name string, firstArg int) {
if sel, ok := args[0].(*ast.SelectorExpr); ok { if sel, ok := args[0].(*ast.SelectorExpr); ok {
if x, ok := sel.X.(*ast.Ident); ok { if x, ok := sel.X.(*ast.Ident); ok {
if x.Name == "os" && strings.HasPrefix(sel.Sel.Name, "Std") { if x.Name == "os" && strings.HasPrefix(sel.Sel.Name, "Std") {
f.Warnf(call.Pos(), "first argument to %s is %s.%s", name, x.Name, sel.Sel.Name) f.Badf(call.Pos(), "first argument to %s is %s.%s", name, x.Name, sel.Sel.Name)
} }
} }
} }
......
...@@ -23,7 +23,7 @@ func (f *File) checkCanonicalFieldTag(field *ast.Field) { ...@@ -23,7 +23,7 @@ func (f *File) checkCanonicalFieldTag(field *ast.Field) {
tag, err := strconv.Unquote(field.Tag.Value) tag, err := strconv.Unquote(field.Tag.Value)
if err != nil { if err != nil {
f.Warnf(field.Pos(), "unable to read struct tag %s", field.Tag.Value) f.Badf(field.Pos(), "unable to read struct tag %s", field.Tag.Value)
return return
} }
...@@ -31,7 +31,7 @@ func (f *File) checkCanonicalFieldTag(field *ast.Field) { ...@@ -31,7 +31,7 @@ func (f *File) checkCanonicalFieldTag(field *ast.Field) {
// new key:value to end and checking that // new key:value to end and checking that
// the tag parsing code can find it. // the tag parsing code can find it.
if reflect.StructTag(tag+` _gofix:"_magic"`).Get("_gofix") != "_magic" { if reflect.StructTag(tag+` _gofix:"_magic"`).Get("_gofix") != "_magic" {
f.Warnf(field.Pos(), "struct field tag %s not compatible with reflect.StructTag.Get", field.Tag.Value) f.Badf(field.Pos(), "struct field tag %s not compatible with reflect.StructTag.Get", field.Tag.Value)
return return
} }
} }
...@@ -64,7 +64,7 @@ func (f *File) checkUntaggedLiteral(c *ast.CompositeLit) { ...@@ -64,7 +64,7 @@ func (f *File) checkUntaggedLiteral(c *ast.CompositeLit) {
// Convert the package name to an import path, and compare to a whitelist. // Convert the package name to an import path, and compare to a whitelist.
path := pkgPath(f, pkg.Name) path := pkgPath(f, pkg.Name)
if path == "" { if path == "" {
f.Warnf(c.Pos(), "unresolvable package for %s.%s literal", pkg.Name, s.Sel.Name) f.Badf(c.Pos(), "unresolvable package for %s.%s literal", pkg.Name, s.Sel.Name)
return return
} }
typeName := path + "." + s.Sel.Name typeName := path + "." + s.Sel.Name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment