Skip to content

Commit 11196f2

Browse files
rscgopherbot
authored andcommitted
internal/pkgdoc: fix rendering of generics like atomic.Pointer
Fixes golang/go#54200. Change-Id: I407b7368c524746b0f14c6ec5495c509794e331a Reviewed-on: https://go-review.googlesource.com/c/website/+/420794 Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Russ Cox <[email protected]> Auto-Submit: Russ Cox <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 9488f16 commit 11196f2

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

cmd/golangorg/server_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package main
66

77
import (
88
"bytes"
9+
"go/build"
910
"net/http/httptest"
1011
"os"
1112
"path/filepath"
@@ -24,10 +25,25 @@ func TestWeb(t *testing.T) {
2425
t.Fatal(err)
2526
}
2627
for _, file := range files {
27-
if filepath.ToSlash(file) != "testdata/live.txt" {
28-
webtest.TestHandler(t, file, h)
28+
switch filepath.ToSlash(file) {
29+
case "testdata/live.txt":
30+
continue
31+
case "testdata/go1.19.txt":
32+
if !haveRelease("go1.19") {
33+
continue
34+
}
35+
}
36+
webtest.TestHandler(t, file, h)
37+
}
38+
}
39+
40+
func haveRelease(release string) bool {
41+
for _, tag := range build.Default.ReleaseTags {
42+
if tag == release {
43+
return true
2944
}
3045
}
46+
return false
3147
}
3248

3349
var bad = []string{

cmd/golangorg/testdata/go1.19.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
GET https://golang.org/pkg/sync/atomic/?m=old
2+
redirect == https://go.dev/pkg/sync/atomic/?m=old
3+
4+
GET https://go.dev/pkg/sync/atomic/?m=old
5+
body contains func (x *Pointer[T]) Load() *T

internal/pkgdoc/doc.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ package pkgdoc
1111

1212
import (
1313
"bytes"
14-
"golang.org/x/website/internal/backport/go/ast"
15-
"golang.org/x/website/internal/backport/go/doc"
16-
"golang.org/x/website/internal/backport/go/token"
1714
"io"
1815
"io/fs"
1916
"io/ioutil"
@@ -29,7 +26,10 @@ import (
2926
"unicode/utf8"
3027

3128
"golang.org/x/website/internal/api"
29+
"golang.org/x/website/internal/backport/go/ast"
3230
"golang.org/x/website/internal/backport/go/build"
31+
"golang.org/x/website/internal/backport/go/doc"
32+
"golang.org/x/website/internal/backport/go/token"
3333
"golang.org/x/website/internal/web"
3434
)
3535

@@ -363,14 +363,14 @@ func addNames(names map[string]bool, decl ast.Decl) {
363363
case *ast.FuncDecl:
364364
name := d.Name.Name
365365
if d.Recv != nil {
366-
var typeName string
367-
switch r := d.Recv.List[0].Type.(type) {
368-
case *ast.StarExpr:
369-
typeName = r.X.(*ast.Ident).Name
370-
case *ast.Ident:
371-
typeName = r.Name
366+
r := d.Recv.List[0].Type
367+
if star, ok := r.(*ast.StarExpr); ok { // *Name
368+
r = star.X
369+
}
370+
if index, ok := r.(*ast.IndexExpr); ok { // Name[T]
371+
r = index.X
372372
}
373-
name = typeName + "_" + name
373+
name = r.(*ast.Ident).Name + "_" + name
374374
}
375375
names[name] = true
376376
case *ast.GenDecl:

0 commit comments

Comments
 (0)