Skip to content

Commit

Permalink
cmd/api: include type arguments in API
Browse files Browse the repository at this point in the history
T[A] and T[B] are different types, but we were writing them both as
just "T". Reported by Russ.

Change-Id: I27db35946b6d3a1fad6c56c785fa6d850ad71d00
Reviewed-on: https://go-review.googlesource.com/c/go/+/558716
Reviewed-by: Robert Findley <[email protected]>
Auto-Submit: Matthew Dempsky <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
mdempsky committed Jan 26, 2024
1 parent a428387 commit b6d1eb7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/cmd/api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,16 @@ func (w *Walker) writeType(buf *bytes.Buffer, typ types.Type) {
buf.WriteByte('.')
}
buf.WriteString(typ.Obj().Name())
if targs := typ.TypeArgs(); targs.Len() > 0 {
buf.WriteByte('[')
for i := 0; i < targs.Len(); i++ {
if i > 0 {
buf.WriteString(", ")
}
w.writeType(buf, targs.At(i))
}
buf.WriteByte(']')
}

case *types.TypeParam:
// Type parameter names may change, so use a placeholder instead.
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/api/testdata/src/pkg/p4/golden.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pkg p4, func NewPair[$0 interface{ M }, $1 interface{ ~int }]($0, $1) Pair
pkg p4, func NewPair[$0 interface{ M }, $1 interface{ ~int }]($0, $1) Pair[$0, $1]
pkg p4, method (Pair[$0, $1]) Second() $1
pkg p4, method (Pair[$0, $1]) First() $0
pkg p4, type Pair[$0 interface{ M }, $1 interface{ ~int }] struct
Expand Down

0 comments on commit b6d1eb7

Please sign in to comment.