Given, say, var f *os.File, a new vet check in CL 14122 diagnoses:
fmt.Printf("%s\n", f.Name)
fmt.Println(f.Name)
but not
fmt.Printf("%v\n", f.Name)
In all three cases the error is that the argument should be f.Name().
Diagnosing Println but not Printf %v seems oddly inconsistent,
so I changed %v to have the check too. In fact, all verbs now have
the check except %p and %T.
Fixes Dave Cheney's confusion when trying to write an example
of the new vet check advertised in the Go 1.6 release notes.
Change-Id: I92fa6a7a1d5d9339a6a59ae4e587a254e633f500
Reviewed-on: https://go-review.googlesource.com/19101
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
This was a mistake made when bringing cmd/vet into the main repo.
Fixes#13416.
Change-Id: I03b512ab944577c56085aea06df8ff5e1acc16d7
Reviewed-on: https://go-review.googlesource.com/17455
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Prior to this change "go tool vet -all -shadow" ran only -shadow check.
Also fix godoc package path in the usage text.
Fixes#13020
Change-Id: I87c60d6b06a02106ae8bff56adb79df032cc4646
Reviewed-on: https://go-review.googlesource.com/16325
Reviewed-by: Russ Cox <rsc@golang.org>
Fix for iOS builder.
Change-Id: I5b6c977b187446c848182a9294d5bed6b5f9f6e4
Reviewed-on: https://go-review.googlesource.com/16633
Run-TryBot: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
This change fixes shadow assignment check in cases when RHS is not an identifier
or a type assertion.
Fixes#12188
Change-Id: I0940df8d9c237ab8b8d3272eb6895e676c75c115
Reviewed-on: https://go-review.googlesource.com/16038
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Recent changes caused vet to build the binary for each Test function.
This is wasteful and will become only more so as more tests are added.
Use testing.Main to build only once.
Verified that compilation errors still appear if the binary cannot be
built.
Before:
real 0m11.169s
user 0m18.328s
sys 0m2.152s
After:
real 0m5.132s
user 0m9.404s
sys 0m1.168s
Of course if the compiler were fast we might not notice, but vet is
a big program and growing bigger all the time, as are the tests.
Change-Id: I209a8fdcace94bc5cec946f5dd365d7191f44c02
Reviewed-on: https://go-review.googlesource.com/14822
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This means bringing over the examples flag and sorting doc.go.
Subsequent changes will generalize the examples flag to a general
test naming flag, but let's start with the original code.
No more changes to golang.org/x/tools please. This should not have
happened (and letting it happen was partly my fault).
Change-Id: Ia879ea1d15d82372df14853f919263125dfb7b96
Reviewed-on: https://go-review.googlesource.com/14821
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
It went out of its way to look for implicit assignments
but never checked explicit assignments.
This detects the root bug for #12099.
Change-Id: I6a6e774cc38749ea8be7cfd58ba6421247b67000
Reviewed-on: https://go-review.googlesource.com/13646
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
Printing a function value is nearly useless outside of debugging, but
can occur by mistake when one forgets to call it. Diagnose this.
I did this myself just the other day and it arose in cl/14031.
Easy to fix and seems worthwhile.
Fixes#12295.
Change-Id: Ice125a84559f0394f7fa7272b5d31ae602b07f83
Reviewed-on: https://go-review.googlesource.com/14122
Reviewed-by: Andrew Gerrand <adg@golang.org>
This was missed when we did the rename months ago
because cmd/vet did not live in the main tree.
Now vet's asmdecl checks will apply to ppc64 assembly too.
Change-Id: I687cba89fef702f29dd118de76a7ca1041c414f6
Reviewed-on: https://go-review.googlesource.com/13677
Reviewed-by: Andrew Gerrand <adg@golang.org>
The one in misc/makerelease/makerelease.go is particularly bad and
probably warrants rotating our keys.
I didn't update old weekly notes, and reverted some changes involving
test code for now, since we're late in the Go 1.5 freeze. Otherwise,
the rest are all auto-generated changes, and all manually reviewed.
Change-Id: Ia2753576ab5d64826a167d259f48a2f50508792d
Reviewed-on: https://go-review.googlesource.com/12048
Reviewed-by: Rob Pike <r@golang.org>
And vice versa.
The flags are tightly coupled so make the connection clear.
Change-Id: I505f76be631ffa6e489a441c2f3c717aa09ec802
Reviewed-on: https://go-review.googlesource.com/11324
Reviewed-by: Andrew Gerrand <adg@golang.org>
The main change is:
golang.org/cl/10800 add pos parameter to Eval; remove New, EvalNode
followed by several cleanups/follow-up fixes:
golang.org/cl/10992 remove global vars in test
golang.org/cl/10994 remove unused scope parameter from NewSignature
golang.org/cl/10995 provide full source file extent to file scope
golang.org/cl/10996 comment fix in resolver.go
golang.org/cl/11004 updated cmd/vet
golang.org/cl/11042 be robust in the presence of incorrect/missing position info
Fixes#9980.
Change-Id: Id4aff688f6a399f76bf92b84c7e793b8da8baa48
Reviewed-on: https://go-review.googlesource.com/11122
Reviewed-by: Alan Donovan <adonovan@google.com>
Running -copylocks over a large corpus generates 1507 warnings.
Of those, only 3 are from the new anonymous function check,
but they are all bugs.
Fixes#10927.
Change-Id: I2672f6871036bed711beec5f88bc39aa8b3b6a94
Reviewed-on: https://go-review.googlesource.com/11051
Reviewed-by: Rob Pike <r@golang.org>
Forgot this one in my previous commit.
Change-Id: Ief089e99bdad24b3bcfb075497dc259d06cc727c
Reviewed-on: https://go-review.googlesource.com/10913
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Might get the Android build passing, or at least going further.
Change-Id: I08f97156a687abe5a3d95203922f4ffd84fbb212
Reviewed-on: https://go-review.googlesource.com/10924
Reviewed-by: David Crawshaw <crawshaw@golang.org>
- remove TODO on non-existing fmt.Formatter type
(type exists now)
- guard uses of imported types against nil
Change-Id: I9ae8e5a448e73c84dec1606ea9d9ed5ddeee8dc6
Reviewed-on: https://go-review.googlesource.com/10777
Reviewed-by: Alan Donovan <adonovan@google.com>
Add .exe to exectable name, so it can be executed on windows.
Use proper windows paths when searching vet output.
Replace Skip with Skipf.
Fixes build
Change-Id: Ife40d8f5ab9d7093ca61c50683a358d4d6a3ba34
Reviewed-on: https://go-review.googlesource.com/10742
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
Reviewed-by: Patrick Mézard <patrick@mezard.eu>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
- s|"golang.org/x/tools/go/exact"|"go/constant"|
- s|"golang.org/x/tools/go/types"|"go/types"|
- removed import of gcimporter
- import "go/importer" instead
- trivial adjustments to make use of go/importer
- adjusted import paths for whitelist.go
Change-Id: I43488ff44c329cd869c92dcc31193fb31bebfd29
Reviewed-on: https://go-review.googlesource.com/10695
Reviewed-by: Rob Pike <r@golang.org>
cp -r x/tools/cmd/vet cmd/vet without any changes.
The next change will adjust the source to use std
repo go/types and friends.
This may (temporarily) break the build; the next
commit (immediately following) will fix it. We do
it in two commits so that we can see the manual
changes.
Change-Id: Ic45dab7066f13923e21f8c61200c8c3fd447b171
Reviewed-on: https://go-review.googlesource.com/10694
Reviewed-by: Rob Pike <r@golang.org>
- clean up the notypes version of the test so it's quiet
- change the package in the buildtag test to avoid confusing godoc
R=golang-dev, minux.ma, bradfitz
CC=golang-dev
https://golang.org/cl/8671049
Analogous to the one for .go files, it's for .s only and is protected
by the verbose flag.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/8030046
This is a totally mechanical change.
Errors are reported for the beginning of the statement, not the end,
so the errchk markers need to be on the opening brace, not the closing
one. It seems this test was never run.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7746050
They should be build-tagged for vet_test not ignore,
and not have a Go package clause.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/8016047
Eliminate false positives when you can tell even without
type information that the literal does not need field tags.
Far too noisy otherwise.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7797043
We can enable/disable type checking with a build tag.
Should simplify cutting the go1.1 distribution free of go/types.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7482045
The only check so far is for self-assignments of the form "expr = expr",
but even that found one instance in the standard library.
R=r, adg, mtj, rsc
CC=golang-dev
https://golang.org/cl/7455048
Fixes#4945.
Most examples in this issue now better, but #10 is incomplete and I'm not
certain how to reproduce it. It actually looks like a go/types problem, since
the type being reported is coming directly from that package.
Please reopen the issue if you disagree.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7448046
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
And fix test. Pointer to unsafe.Pointer tests nothing important...
Also identify the incorrect type: go/types.Type is a Stringer.
Also fix a couple of incorrect format verbs found by new printf checker,
now that we can run it on more files.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7385051
Also restores the checking of _test.go files, which disappeared
as a result of the package-at-a-time change.
Fixes#4895.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7399051
Then mark them with a build tag so they're not compiled into the binary.
They are called test_*.go rather than *_test.go because they are not
for go test. Use make test to test the command.
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7377052
We need go/types to discriminate the Error method from
the error interface and the Error method of the testing package.
Fixes#4753.
R=golang-dev, bradfitz, gri
CC=golang-dev
https://golang.org/cl/7396054
This is a simple refactoring of main.go that will enable the type checker
to be used during vetting.
The change has an unimportant effect on the arguments: it now assumes
that all files named explicitly on the command line belong to the same
package. When run by the go command, this was true already.
Also restore a missing parenthesis from an error message.
R=golang-dev, gri, bradfitz
CC=golang-dev
https://golang.org/cl/7393052
Also:
- faster code for example extraction
- simplify handling of command documentation:
all "main" packages are treated as commands
- various minor cleanups along the way
For commands written in Go, any doc.go file containing
documentation must now be part of package main (rather
then package documentation), otherwise the documentation
won't show up in godoc (it will still build, though).
For commands written in C, documentation may still be
in doc.go files defining package documentation, but the
recommended way is to explicitly ignore those files with
a +build ignore constraint to define package main.
Fixes#4806.
R=adg, rsc, dave, bradfitz
CC=golang-dev
https://golang.org/cl/7333046
Simplify the internal logic for flags controlling what to vet,
by introducing a map of flags that gathers them all together.
This change should simplify the process of adding further flags.
Add a test for untagged struct literals.
Delete a redundant test that was also in the wrong file.
Clean up some ERROR patterns that weren't working.
"make test" passes again.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7305075
Everybody either gets confused and thinks this is
TrimLeft/TrimRight or does this by hand which gets
repetitive looking.
R=rsc, kevlar
CC=golang-dev
https://golang.org/cl/7239044
Re-assigning the return value of an atomic operation to the same variable being operated is a common mistake:
x = atomic.AddUint64(&x, 1)
Add this check to go vet.
Fixes#4065.
R=dvyukov, golang-dev, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/7097048
In a range loop, the presence of a value implies the presence of a key.
However, the presence of a value as an *ast.Ident does not imply that
the key is also an *ast.Ident, thus leading to a panic any time the
two argument form is used where the key is not an identifier.
R=golang-dev, adg, r
CC=golang-dev
https://golang.org/cl/6540045
By default, all are still run, but a particular test can be
selected with the new flags.
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6395053
As in:
const format = "%s"
fmt.Printf(format, "hi")
Also fix a couple of bugs by rewriting the routine.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6099057
Consequently, remove many package Makefiles,
and shorten the few that remain.
gomake becomes 'go tool make'.
Turn off test phases of run.bash that do not work,
flagged with $BROKEN. Future CLs will restore these,
but this seemed like a big enough CL already.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5601057
fix, vet
yacc is also fixed (it was wrong before)
All that's left is the commands used during compilation
This looks like a huge CL, but it's almost all file renames.
The action is in cmd/go/pkg.go, the Makefiles, and .../doc.go.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5595044