Skip to content

Commit 2f5a1a7

Browse files
committed
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>
1 parent 4f7cb80 commit 2f5a1a7

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎go/analysis/passes/stdmethods/stdmethods.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func canonicalMethod(pass *analysis.Pass, id *ast.Ident) {
131131
expectFmt += " (" + argjoin(expect.results) + ")"
132132
}
133133

134-
actual := sign.String()
134+
actual := types.TypeString(sign, (*types.Package).Name)
135135
actual = strings.TrimPrefix(actual, "func")
136136
actual = id.Name + actual
137137

‎go/analysis/passes/stdmethods/testdata/src/a/a.go‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package a
66

7-
import "fmt"
7+
import (
8+
"encoding/xml"
9+
"fmt"
10+
)
811

912
type T int
1013

@@ -18,6 +21,9 @@ func (U) Format(byte) {} // no error: first parameter must be fmt.State to trigg
1821

1922
func (U) GobDecode() {} // want `should have signature GobDecode\(\[\]byte\) error`
2023

24+
// Test rendering of type names such as xml.Encoder in diagnostic.
25+
func (U) MarshalXML(*xml.Encoder) {} // want `method MarshalXML\(\*xml.Encoder\) should...`
26+
2127
type I interface {
2228
ReadByte() byte // want `should have signature ReadByte\(\) \(byte, error\)`
2329
}

0 commit comments

Comments
 (0)