go/analysis/passes/stdmethods: show p.T not dir/p.T in diagnostic

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í <mvdan@mvdan.cc>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Alan Donovan 2018-11-14 09:59:22 -05:00
parent 4f7cb802ba
commit 2f5a1a7a23
2 changed files with 8 additions and 2 deletions

View File

@ -131,7 +131,7 @@ func canonicalMethod(pass *analysis.Pass, id *ast.Ident) {
expectFmt += " (" + argjoin(expect.results) + ")" expectFmt += " (" + argjoin(expect.results) + ")"
} }
actual := sign.String() actual := types.TypeString(sign, (*types.Package).Name)
actual = strings.TrimPrefix(actual, "func") actual = strings.TrimPrefix(actual, "func")
actual = id.Name + actual actual = id.Name + actual

View File

@ -4,7 +4,10 @@
package a package a
import "fmt" import (
"encoding/xml"
"fmt"
)
type T int 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` 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 { type I interface {
ReadByte() byte // want `should have signature ReadByte\(\) \(byte, error\)` ReadByte() byte // want `should have signature ReadByte\(\) \(byte, error\)`
} }