From 2f5a1a7a23ccb071b34c7e63dc1fe20680b98ba4 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 14 Nov 2018 09:59:22 -0500 Subject: [PATCH] go/analysis/passes/stdmethods: show p.T not dir/p.T in diagnostic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Type.String prints named types using the complete package path: "dir/pkg.T" The notation used by canonicalMethod, and the cmd/vet/all whitelist, and the one users want to see, uses only the package name: "pkg.T". Change-Id: If2334a8cca1fb80e947cb105530b946a5a8dec7b Reviewed-on: https://go-review.googlesource.com/c/149597 Reviewed-by: Daniel Martí Reviewed-by: Michael Matloob --- go/analysis/passes/stdmethods/stdmethods.go | 2 +- go/analysis/passes/stdmethods/testdata/src/a/a.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/go/analysis/passes/stdmethods/stdmethods.go b/go/analysis/passes/stdmethods/stdmethods.go index 1c18dbc9..b61c3220 100644 --- a/go/analysis/passes/stdmethods/stdmethods.go +++ b/go/analysis/passes/stdmethods/stdmethods.go @@ -131,7 +131,7 @@ func canonicalMethod(pass *analysis.Pass, id *ast.Ident) { expectFmt += " (" + argjoin(expect.results) + ")" } - actual := sign.String() + actual := types.TypeString(sign, (*types.Package).Name) actual = strings.TrimPrefix(actual, "func") actual = id.Name + actual diff --git a/go/analysis/passes/stdmethods/testdata/src/a/a.go b/go/analysis/passes/stdmethods/testdata/src/a/a.go index 829c5b53..9833f8fd 100644 --- a/go/analysis/passes/stdmethods/testdata/src/a/a.go +++ b/go/analysis/passes/stdmethods/testdata/src/a/a.go @@ -4,7 +4,10 @@ package a -import "fmt" +import ( + "encoding/xml" + "fmt" +) type T int @@ -18,6 +21,9 @@ func (U) Format(byte) {} // no error: first parameter must be fmt.State to trigg func (U) GobDecode() {} // want `should have signature GobDecode\(\[\]byte\) error` +// Test rendering of type names such as xml.Encoder in diagnostic. +func (U) MarshalXML(*xml.Encoder) {} // want `method MarshalXML\(\*xml.Encoder\) should...` + type I interface { ReadByte() byte // want `should have signature ReadByte\(\) \(byte, error\)` }