aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/api/goapi.go
diff options
context:
space:
mode:
authorRobert Findley <rfindley@google.com>2021-10-12 11:54:09 -0400
committerRobert Findley <rfindley@google.com>2021-10-12 22:26:55 +0000
commit78d01be00b68d1f5c3f5eb493f053ba97adc92df (patch)
treee12dc2aa50d6f3ee759f2ea6ff78a504cb3dfae3 /src/cmd/api/goapi.go
parent732f6fa9d552c643b6225dd56689eb653ad61473 (diff)
downloadgo-78d01be00b68d1f5c3f5eb493f053ba97adc92df.tar.xz
cmd/api: use placeholder names for type parameters
Changing type parameter names is not a breaking API change, so we should not include these names in the output of cmd/api. Instead print a placeholder '$<index>' wherever type parameters are referenced. This is valid for cmd/api as there is at most one type parameter list in scope for any exported declaration. If we ever support method type parameters, we'll need to revisit this syntax. Change-Id: I7e677b1dab6ffeb0b79afefdb8d2580bef93891c Reviewed-on: https://go-review.googlesource.com/c/go/+/355389 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/api/goapi.go')
-rw-r--r--src/cmd/api/goapi.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go
index eca113a638..0c61b1b489 100644
--- a/src/cmd/api/goapi.go
+++ b/src/cmd/api/goapi.go
@@ -838,7 +838,8 @@ func (w *Walker) writeType(buf *bytes.Buffer, typ types.Type) {
buf.WriteString(typ.Obj().Name())
case *types.TypeParam:
- buf.WriteString(typ.Obj().Name())
+ // Type parameter names may change, so use a placeholder instead.
+ fmt.Fprintf(buf, "$%d", typ.Index())
default:
panic(fmt.Sprintf("unknown type %T", typ))
@@ -870,7 +871,7 @@ func (w *Walker) writeTypeParams(buf *bytes.Buffer, tparams *types.TypeParamList
buf.WriteString(", ")
}
tp := tparams.At(i)
- buf.WriteString(tp.Obj().Name())
+ w.writeType(buf, tp)
if withConstraints {
buf.WriteByte(' ')
w.writeType(buf, tp.Constraint())