aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vet/testdata
diff options
context:
space:
mode:
authorDaniel Martí <mvdan@mvdan.cc>2018-11-06 21:35:23 +0000
committerDaniel Martí <mvdan@mvdan.cc>2018-11-09 14:58:47 +0000
commit4d913b332cf161df7c4f3717c602d491d7ac01dd (patch)
tree4e1a692bb45e87597c48f3903f4cb6988572edde /src/cmd/vet/testdata
parentedb2d1cbf23c1a638837f21bc7dd51a0807ab236 (diff)
downloadgo-4d913b332cf161df7c4f3717c602d491d7ac01dd.tar.xz
cmd/vet: fix printf false negative with nested pointers
Pointers to compound objects (structs, slices, arrays, maps) are only followed by fmt if the pointer is at the top level of an argument. This is to minimise the chances of fmt running into loops. However, vet did not follow this rule. It likely doesn't help that fmt does not document that restriction well, which is being tracked in #28625. Updates #27672. Change-Id: Ie9bbd9b974eda5ab9a285986d207ef92fca4453e Reviewed-on: https://go-review.googlesource.com/c/147997 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/cmd/vet/testdata')
-rw-r--r--src/cmd/vet/testdata/print.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/cmd/vet/testdata/print.go b/src/cmd/vet/testdata/print.go
index b2289bc2ac..994902d01d 100644
--- a/src/cmd/vet/testdata/print.go
+++ b/src/cmd/vet/testdata/print.go
@@ -234,7 +234,7 @@ func PrintfTests() {
Printf("%T", someFunction) // ok: maybe someone wants to see the type
// Bug: used to recur forever.
Printf("%p %x", recursiveStructV, recursiveStructV.next)
- Printf("%p %x", recursiveStruct1V, recursiveStruct1V.next)
+ Printf("%p %x", recursiveStruct1V, recursiveStruct1V.next) // ERROR "Printf format %x has arg recursiveStruct1V\.next of wrong type \*testdata\.RecursiveStruct2"
Printf("%p %x", recursiveSliceV, recursiveSliceV)
Printf("%p %x", recursiveMapV, recursiveMapV)
// Special handling for Log.
@@ -670,4 +670,12 @@ func PointersToCompoundTypes() {
intMap := map[int]int{3: 4}
fmt.Printf("%s", &intMap) // ERROR "Printf format %s has arg &intMap of wrong type \*map\[int\]int"
+
+ type T2 struct {
+ X string
+ }
+ type T1 struct {
+ X *T2
+ }
+ fmt.Printf("%s\n", T1{&T2{"x"}}) // ERROR "Printf format %s has arg T1{&T2{.x.}} of wrong type testdata\.T1"
}