From 7f284f85f908909a498663d54da689e56cd38e73 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 13 Feb 2013 22:34:37 -0500 Subject: [PATCH] cmd/vet: drop column information from error The column information can be misleading. R=golang-dev, dsymonds, r CC=golang-dev https://golang.org/cl/7300100 --- src/cmd/vet/main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go index c7676e22f1..90ae1daf7e 100644 --- a/src/cmd/vet/main.go +++ b/src/cmd/vet/main.go @@ -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. -- 2.48.1