diff options
author | Daniel Martà <mvdan@mvdan.cc> | 2018-01-29 09:50:50 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2018-01-30 14:35:34 +0000 |
commit | 1f85917fb618a27222ba0253c5dd4fdfdbca2fd2 (patch) | |
tree | dc709809b500b0ad6a33b08554f19131e9edafdb /src/cmd/vet/main.go | |
parent | 8c1f21d9a2674dd9a410e0af94adf6fa7d2877d2 (diff) | |
download | go-1f85917fb618a27222ba0253c5dd4fdfdbca2fd2.tar.gz go-1f85917fb618a27222ba0253c5dd4fdfdbca2fd2.zip |
cmd/vet: **T is not Stringer if *T has a String method
vet recorded what types had String methods defined on them, but it did
not record whether the receivers were pointer types. That information is
important, as the following program is valid:
type T string
func (t *T) String() string {
return fmt.Sprint(&t) // prints address
}
Teach vet that, if *T is Stringer, **T is not.
Fixes #23550.
Change-Id: I1062e60e6d82e789af9cca396546db6bfc3541e8
Reviewed-on: https://go-review.googlesource.com/90417
Run-TryBot: Daniel Martà <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/cmd/vet/main.go')
-rw-r--r-- | src/cmd/vet/main.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go index 807e800959..7265aa6f57 100644 --- a/src/cmd/vet/main.go +++ b/src/cmd/vet/main.go @@ -195,9 +195,11 @@ type File struct { // Parsed package "foo" when checking package "foo_test" basePkg *Package - // The objects that are receivers of a "String() string" method. + // The keys are the objects that are receivers of a "String() + // string" method. The value reports whether the method has a + // pointer receiver. // This is used by the recursiveStringer method in print.go. - stringers map[*ast.Object]bool + stringerPtrs map[*ast.Object]bool // Registered checkers to run. checkers map[ast.Node][]func(*File, ast.Node) |