Skip to content
This repository has been archived by the owner on Sep 1, 2018. It is now read-only.

Commit

Permalink
Port newer signString from unparam
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdan committed Mar 27, 2017
1 parent 4372118 commit 4e43da7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
3 changes: 1 addition & 2 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (p *pkgTypes) ifaceOf(t string) string {
func (p *pkgTypes) getTypes(pkg *types.Package) {
p.ifaces = make(map[string]string)
p.funcs = make(map[string]bool)
path := pkg.Path()
addTypes := func(impPath string, ifs map[string]string, funs map[string]bool, top bool) {
fullName := func(name string) string {
if !top {
Expand All @@ -48,5 +47,5 @@ func (p *pkgTypes) getTypes(pkg *types.Package) {
addTypes(imp.Path(), ifs, funs, false)
}
ifs, funs := fromScope(pkg.Scope())
addTypes(path, ifs, funs, true)
addTypes(pkg.Path(), ifs, funs, true)
}
26 changes: 13 additions & 13 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,24 @@ func funcMapString(iface map[string]string) string {
return b.String()
}

func tupleStrs(t *types.Tuple) []string {
l := make([]string, t.Len())
func tupleJoin(buf *bytes.Buffer, t *types.Tuple) {
buf.WriteByte('(')
for i := 0; i < t.Len(); i++ {
l[i] = t.At(i).Type().String()
if i > 0 {
buf.WriteString(", ")
}
buf.WriteString(t.At(i).Type().String())
}
return l
buf.WriteByte(')')
}

// signString is similar to Signature.String(), but it ignores
// param/result names.
func signString(sign *types.Signature) string {
ps := tupleStrs(sign.Params())
rs := tupleStrs(sign.Results())
if len(rs) == 0 {
return fmt.Sprintf("(%s)", strings.Join(ps, ", "))
}
if len(rs) == 1 {
return fmt.Sprintf("(%s) %s", strings.Join(ps, ", "), rs[0])
}
return fmt.Sprintf("(%s) (%s)", strings.Join(ps, ", "), strings.Join(rs, ", "))
var buf bytes.Buffer
tupleJoin(&buf, sign.Params())
tupleJoin(&buf, sign.Results())
return buf.String()
}

func interesting(t types.Type) bool {
Expand Down

0 comments on commit 4e43da7

Please sign in to comment.