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

22 Commits

Author SHA1 Message Date
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
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
Rob Pike
797431e1a3 go.tools/cmd/vet: fix printf analysis for structs.
The old code only got it right for Stringers (etc.) and a few other simple cases.
But the rule used by fmt.Printf for non-Stringers is that pointers to structs
print as pointers, the rest must satisfy the format verb element-wise.
Thus for example
        struct {a int, b []byte}
prints with %d and %q (sic) but not %g.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12340043
2013-08-02 22:52:38 +10:00
Rob Pike
2a8b9debdd go.tools/cmd/vet: don't complain about empty interface values in printf
R=dsymonds
CC=golang-dev
https://golang.org/cl/12005047
2013-07-30 15:51:35 +10:00
Rob Pike
5ba51116ee go.tools/cmd/vet: treat arrays like slices in the printf checks.
The analysis for types.Array was just missing. It's the same as a slice,
but we can't share code easily because the types differ, so we just dup it.

R=dsymonds
CC=golang-dev
https://golang.org/cl/12041045
2013-07-30 14:00:52 +10:00
David Symonds
573374c476 cmd/vet: Fix handling of non-Stringer arguments.
First, %v and %T accept any arguments, so they should never warn.
Second, pointer types were not handled in matchArgType.
Third, the default response for matchArgType should be false.

R=r
CC=adonovan, golang-dev
https://golang.org/cl/12038050
2013-07-30 13:15:31 +10:00
Alan Donovan
25f3e0fbde go.tools/cmd/vet: improvements to static checking of printf calls.
Details:
- added support for complex numbers as distinct from floats:
  %[efg] allows complex; %b does not.
- %p: only Signature, Map, Chan, Slice, unsafe.Pointer allowed.
- %s: allow []byte.
- allow a verb to match map[K]V and []T if it matches K/V/T,
  e.g. %d now matches []int.  i.e. matching is recursive.
- use go/types' constant folding.  literal() is gone.
- group cases together.

Added tests.

R=gri, r
CC=golang-dev
https://golang.org/cl/10895043
2013-07-15 18:37:49 -04:00
Rob Pike
b042505490 go.tools/cmd/vet: use types.Eval to simplify some checking.
Depends on CL 10748044

R=gri
CC=golang-dev
https://golang.org/cl/11206043
2013-07-13 07:52:00 +10:00
Rob Pike
6740bb0838 go.tools/cmd/vet: delete the word "only" from a warning
No semantic change.

R=dsymonds, rsc
CC=golang-dev
https://golang.org/cl/10516043
2013-06-24 12:56:35 -07:00
Rob Pike
331c428e76 go.tools/cmd/vet: add check for shadowed variables
Experimental feature. It's too noisy yet to be enabled by default,
so it must be enabled explicitly by
        go tool vet -shadow *.go
or
        go tool vet -shadow directory
(The go command does not know about the -shadow flag.)

Fixes golang/go#5634.

R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/10409047
2013-06-21 11:27:53 -07:00
Rob Pike
df787c2073 go.tools/cmd/vet: check for missing printf verb
A trailing % resulted in a bad error message.
Also clean up a couple of dregs left over from the
refactoring to add indexed formats.

R=dsymonds
CC=golang-dev
https://golang.org/cl/10336044
2013-06-18 08:21:06 -07:00
Rob Pike
3402cf10ab go.tools/cmd/vet: verify printf for String and Error implementers
Fixes golang/go#5624.

R=adonovan
CC=gobot, golang-dev, gri
https://golang.org/cl/9657048
2013-06-06 16:05:14 -07:00
Rob Pike
838e9a8987 go.tools/cmd/vet: check indexed arguments in printf
Refactor the printf parser to be easier to understand.

R=gri
CC=golang-dev
https://golang.org/cl/9909043
2013-05-31 16:31:01 -04:00
Rob Pike
c7f7fa1381 cmd/vet: simplify format checker
Simplify the code a bit, get it working after recent go/types changes,
and handle "%*%" just in case. Preparation for handling argument indexing.

R=gri
CC=golang-dev
https://golang.org/cl/9747045
2013-05-28 15:37:34 -04:00
Rob Pike
bf87b9f0f5 go.tools/cmd/vet: use "go test" to test
- remove Makefile
- move test data into a subdirectory
- encapsulate the invocation of errchk into a standard Test using os.exec

R=golang-dev, minux.ma, rsc
CC=golang-dev
https://golang.org/cl/9509045
2013-05-22 10:20:50 -07:00