1
0
mirror of https://github.com/golang/go synced 2024-10-01 03:38:32 -06:00
Commit Graph

77 Commits

Author SHA1 Message Date
Rob Pike
cd9959d796 go.tools/cmd/vet: validate calls to t.Log and t.Logf
Be careful not to complain about math.Log and cmplx.Log.
Seems worthwhile since t.Log and t.Logf are often written but
rarely executed.

Nothing new turned up in the standard library.

Fixes golang/go#8504.

LGTM=josharian, dsymonds
R=golang-codereviews, josharian, dsymonds
CC=golang-codereviews
https://golang.org/cl/130490043
2014-08-25 12:31:49 -07:00
Rob Pike
671b9204b8 go.tools/cmd/vet: change message for range check
s/enclosed by function/captured by func literal/
Users complained. They often do.

LGTM=josharian, adg
R=golang-codereviews, josharian, nightlyone, minux, adg
CC=golang-codereviews
https://golang.org/cl/132080043
2014-08-24 17:26:18 -07:00
Keith Randall
562b65fda7 vet: LEA* opcodes don't need to have matching length source and destination.
LGTM=rsc
R=golang-codereviews, khr, rsc
CC=golang-codereviews
https://golang.org/cl/117950044
2014-07-21 21:15:39 -07:00
Josh Bleecher Snyder
7da5f193b7 go.tools/cmd/vet: detect stupid boolean conditions
This CL introduces two vet checks. Statistics and code below are from a recent 50mb corpus of public code.

1. Check for redundant conjunctions and disjunctions. This check caught 26 instances, of which 20 were clearly copy/paste bugs and 6 appeared to be mere duplication. A typical example:

if xResolution < 0 || xResolution < 0 {
        panic("SetSize(): width < 0 || height < 0")
}

2. Check for expressions of the form 'x != c1 || x != c2' or 'x == c1 && x == c2', with c1 and c2 constant expressions. This check caught 16 instances, of which all were bugs. A typical example:

if rf.uri.Scheme != "http" || rf.uri.Scheme != "ftp" {
        rf.uri.Scheme = "file"
}

Fixes golang/go#7622.

LGTM=rsc, r
R=golang-codereviews, jscrockett01, r, gri, rsc
CC=golang-codereviews
https://golang.org/cl/98120043
2014-07-02 10:39:57 -07:00
Josh Bleecher Snyder
95a7aeb192 go.tools/cmd/vet: don't panic on commented-out asm
Really two fixes: Don't panic on bad instructions and don't complain about commented out instructions.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/110070044
2014-06-20 16:52:48 -07:00
Josh Bleecher Snyder
9d6cc5fd08 go.tools/cmd/vet: prevent panic on goto without label
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/107260043
2014-06-20 11:08:45 -07:00
Josh Bleecher Snyder
d46b792624 cmd/vet: check for use of json/xml struct tags with unexported fields
This is a common source of bugs, particularly for those new to Go. Running this on a corpus of public code flagged 114 instances.

This check may need to be updated once issue 7363 is resolved.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews
https://golang.org/cl/91010047
2014-06-13 18:44:31 -07:00
David Symonds
f895b43688 vet: Rearrange checkers to use a registration system.
This removes much of the AST logic out of main.go,
and makes it easier to build custom vet binaries

The trade-off in this change is for flexibility.
There's very little change in the per-check files,
a lot less code in main.go (specifically the AST walking
logic has shrunk), and it makes it much easier to build
custom vet binaries simply by dropping new source files
in the directory.

LGTM=josharian, r
R=r, josharian, kamil.kisiel
CC=golang-codereviews
https://golang.org/cl/83400043
2014-06-13 15:04:45 +10:00
Rob Pike
4374c8910f go.tools/cmd/vet: clean up formatting of the package document
It was very ugly; a little tweaking helps godoc parse it better.
Also make unsafeptr.go not own the package doc (add a blank line)
and put one more sentence about that check into doc.go.

Fixes golang/go#7925.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/98370044
2014-05-19 11:34:31 -07:00
Russ Cox
322a5f1b4c cmd/vet: add amd64p32 (nacl) support to asmdecl check
Also add 'ErrorString', for checking Plan 9's package syscall.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/93410045
2014-05-19 12:31:38 -04:00
Russ Cox
d8a81d8377 cmd/vet: fix line number in asm errors
Before:
: asm_amd64.s:16: [amd64] invalid offset new+16(FP); expected new+8(FP)
: asm_amd64.s:26: [amd64] invalid offset new+16(FP); expected new+8(FP)

After:
asm_amd64.s:16: [amd64] invalid offset new+16(FP); expected new+8(FP)
asm_amd64.s:26: [amd64] invalid offset new+16(FP); expected new+8(FP)

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/91510043
2014-05-19 12:31:28 -04:00
Russ Cox
b752e9ffdf cmd/vet: diagnose use of unsafe.Pointer to convert integer to pointer
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/100470044
2014-05-15 15:32:51 -04:00
Robert Obryk
91b1b28499 go.tools/cmd/vet: fix a panic on invalid AddInt
Ignore calls to various flavours of atomic.AddInt with a wrong
number of arguments.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/91370045
2014-05-14 12:16:58 -07:00
David Symonds
7c69950f7f vet: Don't consider %T for recursive stringers.
Unlike the other anyType verbs, %T never calls String.

Fixes golang/go#7540.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/75580045
2014-03-14 16:08:04 +11:00
David Symonds
d4c8d5dae3 vet: Broaden suppression of recursive stringer warning.
Updates golang/go#6212.

LGTM=r, gri
R=r, gri
CC=golang-codereviews
https://golang.org/cl/75130043
2014-03-13 11:19:34 +11:00
Rob Pike
e239f1b3f2 go.tools/cmd/vet: don't check for shadowing of blank identifier
It's pointless.
Also this fixes a crash, because the blank identifier no longer appears as a
defined object after CL 74190043 so we were getting nil pointer violations.
Even better, we get to re-enable a disabled test.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/75140043
2014-03-13 10:27:55 +11:00
Robert Griesemer
ea79d922e6 go.tools/go/vet: temporarily disable some tests to fix build
Revert this CL once a proper fix is in place.

LGTM=adonovan
R=r, adonovan
CC=golang-codereviews
https://golang.org/cl/74930043
2014-03-12 11:56:25 -07:00
Rob Pike
6bd3206b1f go.tools/cmd/vet: allow checks to be disabled explicitly as well as set explicitly
Now we can say
        vet -printf=false
to disable the printf test but run all others.
Implemented by creating a tri-state boolean flag that records whether it has been
set explicitly; before this, -printf=false was not distinguishable from not having
mentioned the printf flag at all.

Fixes golang/go#7422.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/72330043
2014-03-07 16:02:49 +11:00
Rob Pike
95c9b7bad1 go.tools/cmd/vet: replace warnings by errors
Over time, a number of modules were added that used Warn instead of Bad
to report problems with the code, but the documentation states that
if there is a problem, the exit code must be 1, not 0. Warn does not set the
exit code and should be used only for internal errors and messages
triggered by the -v flag.

There's nothing substantive here except calling the other function in a few
places.

Fixes golang/go#7017.

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=golang-codereviews
https://golang.org/cl/71860044
2014-03-07 15:31:28 +11:00
Rob Pike
31c219bef7 go.tools/cmd/vet: change reporting of incorrect error count in Printf
The old code was misleading in saying how many args were present.
Change the wording of the message to be unambiguous and change
the presentation of the format to include the full directive, making
it easier to correlate with the input (and fixing a silent bug).
Fixes golang/go#6248.

LGTM=dsymonds
R=golang-codereviews, dsymonds
CC=golang-codereviews
https://golang.org/cl/69120044
2014-03-04 15:41:49 +11:00
Alan Donovan
ced954c167 go.tools/go/types: split Info.Objects map into Defs and Uses.
An identifier X in anonymous struct field struct{X} is both a
definition of a field (*Var) and reference to a type
(*TypeName).  Now that we have split the map, we can capture
both of these aspects.

Interestingly, every client but one was going to extra effort
to iterate over just the uses or just the defs; this
simplifies them.

Also, fix two bug related to tagless switches:
- An entry was being recorded in the Object map for a piece of
  synthetic syntax.
- The "true" identifier was being looked up in the current scope,
  which allowed perverse users to locally redefine it.  Now
  we use the bool (not untyped boolean) constant true, per the
  consequent clarification of the spec (issue 7404).

+ tests.

Fixes golang/go#7276

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/68270044
2014-02-27 13:21:59 -05:00
Rob Pike
ee3eeefaa3 cmd/vet: check for nil result set in isStringer
Fixes golang/go#7149.

LGTM=gri
R=golang-codereviews, gri
CC=golang-codereviews
https://golang.org/cl/68260044
2014-02-24 11:39:42 -08:00
Rob Pike
cde4d316d2 go.tools/cmd/vet: docs: explain the command line interface better
How it handles packages vs. directories vs. files was not explained.

LGTM=rsc
R=golang-codereviews, gobot, rsc
CC=golang-codereviews
https://golang.org/cl/67150043
2014-02-24 10:44:02 -08:00
David du Colombier
374c600cae go.tools/cmd/vet: disable TestVet on Plan 9
LGTM=minux.ma
R=golang-codereviews, minux.ma
CC=golang-codereviews
https://golang.org/cl/64410043
2014-02-20 21:43:24 +01:00
Andrew Gerrand
47596b4b81 go.tools/cmd/vet: add stable checks to doc.go
These are the simplest possible descriptions of each command.
They may be fleshed out later.

Fixes golang/go#7298.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/61480044
2014-02-13 11:05:01 +11:00
Alan Donovan
1f29e74bfa go.tools/go/types: remove Type.MethodSet() method.
Method-set caching is now performed externally using a MethodSetCache (if desired), not by the Types themselves.

This a minor deoptimization due to the extra maps, but avoids a situation in which method-sets are computed and frozen prematurely. (See b/7114)

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/61430045
2014-02-11 16:49:27 -05:00
Robert Griesemer
20efc5ba73 go.tools/go/types: use init cycle tracking for all const and var cycles
Also rename types.Assertable -> types.AssertableTo per adonovan.

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/59680044
2014-02-03 16:02:56 -08:00
Robert Griesemer
4dcaee97b2 go.tools/cmd/vet: use new Assertable predicate (fix build)
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/59210045
2014-02-03 11:39:10 -08:00
Alan Donovan
64ec206bfd go.tools/go/types: combine Info.{Types,Values} maps.
This results in significant improvement to type-checking time:
it reduces by 4% the entire running time of ssa/stdlib_test
(GOMAXPROCS=8, n=7).

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/57770043
2014-01-28 16:46:24 -05:00
Robert Griesemer
ebfa4efbc4 go.tools/go/types: cleanup: more consistent exported predicate names
Renamed predicates:
IsIdentical -> Identical
IsAssignableTo -> AssignableTo
Signature.IsVariadic -> Signature.Variadic
Object.IsExported -> Object.Exported

LGTM=adonovan
R=adonovan
CC=golang-codereviews
https://golang.org/cl/53370043
2014-01-28 10:57:56 -08:00
Rob Pike
bae6bf6180 go.tools/cmd/vet: improve error message for build tag problems
Fixes golang/go#6979.

R=golang-dev, dave, iant
CC=golang-dev
https://golang.org/cl/37720048
2013-12-18 16:06:56 -08:00
Josh Bleecher Snyder
866b24e166 cmd/vet: check for sync types being copied during function calls
Using a type containing a sync type directly
in a function call (whether as a receiver,
a param, or a return value) is an easy way
to accidentally copy a lock or other sync primitive.
Check for it.

The test as implemented does not provide 100%
coverage; see the discussion near the bottom of
testdata/copylock.go for shortcomings.

Fixes golang/go#6729.

R=adg, r, dsymonds
CC=golang-dev
https://golang.org/cl/23420043
2013-12-09 20:14:28 -08:00
Robert Griesemer
27563ff576 go.tools/go/types: move gcimporter to its own package
- fixed a couple of TODOs
- various cleanups along the way
- adjusted clients

Once submitted, clients of go/types that don't explicitly
specify Config.Import will need to add the extra import:

import _ "code.google.com/p/go.tools/go/gcimporter"

to install the default (gc) importer in go/types.

R=adonovan, gri
CC=golang-dev
https://golang.org/cl/26390043
2013-11-14 14:11:43 -08:00
Rob Pike
2afbb1cd5f go.tools/cmd/vet: handle symbolic TEXT annotations
The symbolic names such as NOSPLIT for annotations on the TEXT
directive appeared after vet started checking .s files. This CL tweaks
the regular expression to allow CAPITALS and the symbols | and +
as well as digits in that field, and interprets NOSPLIT as equivalent
to 7 in that field. All magic.

Fixes golang/go#6695

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/18700044
2013-11-01 11:49:11 -07:00
Robert Griesemer
f50f6c858a go.tools/go/types: nil is not a constant + misc. cleanups
- removed support for nil constants from go/exact
- instead define a singleton Nil Object (the nil _value_)
- in assignments, follow more closely spec wording
  (pending spec CL 14415043)
- removed use of goto in checker.unary
- cleanup around handling of isRepresentable for
  constants, with better error messages
- fix missing checks in checker.convertUntyped
- added isTyped (== !isUntyped) and isInterface predicates
- fixed hasNil predicate: unsafe.Pointer also has nil
- adjusted ssa per adonovan
- implememted types.Implements (wrapper arounfd types.MissingMethod)
- use types.Implements in vet (and fix a bug)

R=adonovan, r
CC=golang-dev
https://golang.org/cl/14438052
2013-10-09 14:17:25 -07:00
Dominik Honnef
d5044c7ed2 go.tools/cmd/vet: Update canonical method check for new xml.Marshaler/Unmarshaler interfaces
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/14484043
2013-10-07 11:10:36 -07:00
Rob Pike
6ad0d283e1 go.tools/cmd/vet: handle recursive structs and slices.
Fixes golang/go#6309

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13386046
2013-09-18 12:57:59 +10:00
Rob Pike
ece05f910e go.tools/cmd/vet: update for fmt handling %b for complex numbers
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/13490048
2013-09-16 08:18:27 +10:00
Rob Pike
bc5f637240 go.tools/cmd/vet: assume implementations of fmt.Formatter print just fine
Update golang/go#6212
See issue 6259.
When that is resolved, we can do a better job. Until then, we just see if the
type has a method called Format and, if so, assume it's a Formatter and so
there's nothing to check.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13267043
2013-08-28 11:24:43 +10:00
Andrew Gerrand
890e4c0731 go.tools/cmd/vet: exclude "%#v" from recursive stringer check
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/13163043
2013-08-22 11:44:39 +10:00
Andrew Gerrand
f6a22edf66 go.tools/cmd/vet: relax recursive stringer check
For the pointer receiver x, fmt.Sprintf(*x) does not invoke x's String
method.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12971045
2013-08-22 11:29:44 +10:00
Andrew Gerrand
de72360261 go.tools/cmd/vet: fix build of testdata package
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13144043
2013-08-21 11:08:25 +10:00
Andrew Gerrand
61d86e98d5 go.tools/cmd/vet: check for recursive stringers
Fixes golang/go#6129.

R=r
CC=golang-dev
https://golang.org/cl/12936046
2013-08-21 11:07:53 +10:00
Brad Fitzpatrick
3e29592dba cmd/vet: move whitelist to its own package
App Engine needs the whitelist file and it's cleaner if it's
in its own package where it can be imported directly, without
pushing composite.go through a pile of sed.

R=dsymonds, r
CC=golang-dev
https://golang.org/cl/12746045
2013-08-20 15:39:49 -07:00
Andrew Gerrand
74ecc2c09b go.tools/cmd/vet: detect useless function comparisons
Also fix bug in types.go discovered by this check.

Fixes golang/go#5347.

R=golang-dev, dsymonds, r
CC=golang-dev
https://golang.org/cl/13102043
2013-08-20 16:11:01 +10:00
David Symonds
a7c698b070 undo CL 12811043 / 44387735a77d
Not the right thing to do.
Fixes golang/go#6148.

««« original CL description
cmd/vet: flag redundant invocations of String and Error methods in printf calls.

R=r
CC=golang-dev
https://golang.org/cl/12811043
»»»

R=r
CC=golang-dev
https://golang.org/cl/13034043
2013-08-19 11:12:44 +10:00
David Symonds
c0b6badc83 cmd/vet: flag redundant invocations of String and Error methods in printf calls.
R=r
CC=golang-dev
https://golang.org/cl/12811043
2013-08-13 13:47:58 +10:00
Robert Griesemer
45e3d57f32 go.tools/cmd/vet: enable test (fix build)
R=r
TBR=r
CC=golang-dev
https://golang.org/cl/12482043
2013-08-05 14:02:52 -07:00
Rob Pike
c333e7a7b6 go.tools/cmd/vet: fix go.tools build
TBR: gri

I cannot create an issue on the tracker for some reason, so here it is:
go vet contains this snippet:

        if types.IsAssignableTo(typ, errorType) || types.IsAssignableTo(typ, stringerType) {

It's getting the wrong answer: It claims

interface {
        f()
}

or even

interface {
        f() float64
}

matches the Error and Stringer interfaces. Both of them.  This causes a test failure:
$ go test code.google.com/p/go.tools/cmd/vet
BUG: errchk: testdata/print.go:124: missing expected error: '"for printf verb %s of wrong type"'
$
This worked until very recently.

R=gri
CC=golang-dev
https://golang.org/cl/12398043
2013-08-03 15:56:56 +10:00
Rob Pike
aecec2f502 go.tools/cmd/vet: the composite test is about keys, not tags
Fix the confusion.
No semantic change, just some renamings.

Fixes golang/go#6017.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12394043
2013-08-03 12:19:59 +10:00