diff --git a/go/analysis/passes/stdmethods/stdmethods.go b/go/analysis/passes/stdmethods/stdmethods.go index b61c32208b..8349511224 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 := types.TypeString(sign, (*types.Package).Name) + actual := typeString(sign) actual = strings.TrimPrefix(actual, "func") actual = id.Name + actual @@ -139,6 +139,10 @@ func canonicalMethod(pass *analysis.Pass, id *ast.Ident) { } } +func typeString(typ types.Type) string { + return types.TypeString(typ, (*types.Package).Name) +} + func argjoin(x []string) string { y := make([]string, len(x)) for i, s := range x { @@ -178,5 +182,5 @@ func matchParamType(fset *token.FileSet, pkg *types.Package, expect string, actu } // Overkill but easy. - return actual.String() == expect + return typeString(actual) == expect } diff --git a/go/analysis/passes/stdmethods/testdata/src/a/a.go b/go/analysis/passes/stdmethods/testdata/src/a/a.go index 9833f8fd1f..de240a3bef 100644 --- a/go/analysis/passes/stdmethods/testdata/src/a/a.go +++ b/go/analysis/passes/stdmethods/testdata/src/a/a.go @@ -24,6 +24,10 @@ func (U) GobDecode() {} // want `should have signature GobDecode\(\[\]byte\) err // Test rendering of type names such as xml.Encoder in diagnostic. func (U) MarshalXML(*xml.Encoder) {} // want `method MarshalXML\(\*xml.Encoder\) should...` +func (U) UnmarshalXML(*xml.Decoder, xml.StartElement) error { // no error: signature matches xml.Unmarshaler + return nil +} + type I interface { ReadByte() byte // want `should have signature ReadByte\(\) \(byte, error\)` }