]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: drop column information from error
authorRuss Cox <rsc@golang.org>
Thu, 14 Feb 2013 03:34:37 +0000 (22:34 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 14 Feb 2013 03:34:37 +0000 (22:34 -0500)
The column information can be misleading.

R=golang-dev, dsymonds, r
CC=golang-dev
https://golang.org/cl/7300100

src/cmd/vet/main.go

index c7676e22f104a13ee79bfbec4dd0447adb039a85..90ae1daf7e4a91a5f40256b74e1cc0a074bc4f5e 100644 (file)
@@ -195,16 +195,22 @@ func (f *File) Badf(pos token.Pos, format string, args ...interface{}) {
        setExit(1)
 }
 
+func (f *File) loc(pos token.Pos) string {
+       // Do not print columns. Because the pos often points to the start of an
+       // expression instead of the inner part with the actual error, the
+       // precision can mislead.
+       posn := f.fset.Position(pos)
+       return fmt.Sprintf("%s:%d: ", posn.Filename, posn.Line)
+}
+
 // Warn reports an error but does not set the exit code.
 func (f *File) Warn(pos token.Pos, args ...interface{}) {
-       loc := f.fset.Position(pos).String() + ": "
-       fmt.Fprint(os.Stderr, loc+fmt.Sprintln(args...))
+       fmt.Fprint(os.Stderr, f.loc(pos)+fmt.Sprintln(args...))
 }
 
 // Warnf reports a formatted error but does not set the exit code.
 func (f *File) Warnf(pos token.Pos, format string, args ...interface{}) {
-       loc := f.fset.Position(pos).String() + ": "
-       fmt.Fprintf(os.Stderr, loc+format+"\n", args...)
+       fmt.Fprintf(os.Stderr, f.loc(pos)+format+"\n", args...)
 }
 
 // walkFile walks the file's tree.