internal/godoc/internal/doc: update go go1.18beta1
Incorporate the changes in go/doc made for generics into our fork of
go/doc.
For golang/go#48264
Change-Id: Ic31d0d58ffbe731b5d425506564ecda3774ae840
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/382975
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/go.mod b/go.mod
index bb1f411..4a399f5 100644
--- a/go.mod
+++ b/go.mod
@@ -1,25 +1,20 @@
module golang.org/x/pkgsite
-go 1.16
+go 1.18
require (
cloud.google.com/go/cloudtasks v1.0.0
- cloud.google.com/go/container v1.0.0 // indirect
cloud.google.com/go/errorreporting v0.1.0
cloud.google.com/go/logging v1.4.2
- cloud.google.com/go/monitoring v1.1.0 // indirect
cloud.google.com/go/profiler v0.1.1
cloud.google.com/go/secretmanager v1.0.0
cloud.google.com/go/storage v1.18.2
- cloud.google.com/go/trace v1.0.0 // indirect
contrib.go.opencensus.io/exporter/prometheus v0.1.0
contrib.go.opencensus.io/exporter/stackdriver v0.13.4
contrib.go.opencensus.io/integrations/ocsql v0.1.4
github.com/Masterminds/squirrel v1.5.2
github.com/alicebob/miniredis/v2 v2.17.0
github.com/andybalholm/cascadia v1.3.1
- github.com/aws/aws-sdk-go v1.34.29 // indirect
- github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
github.com/evanw/esbuild v0.14.10
github.com/ghodss/yaml v1.0.0
github.com/go-git/go-billy/v5 v5.3.1
@@ -52,3 +47,64 @@
google.golang.org/grpc v1.43.0
google.golang.org/protobuf v1.27.1
)
+
+require (
+ cloud.google.com/go v0.99.0 // indirect
+ cloud.google.com/go/container v1.0.0 // indirect
+ cloud.google.com/go/monitoring v1.1.0 // indirect
+ cloud.google.com/go/trace v1.0.0 // indirect
+ github.com/Microsoft/go-winio v0.5.0 // indirect
+ github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
+ github.com/acomagu/bufpipe v1.0.3 // indirect
+ github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
+ github.com/aws/aws-sdk-go v1.34.29 // indirect
+ github.com/aymerick/douceur v0.2.0 // indirect
+ github.com/beorn7/perks v1.0.1 // indirect
+ github.com/census-instrumentation/opencensus-proto v0.3.0 // indirect
+ github.com/cespare/xxhash/v2 v2.1.2 // indirect
+ github.com/chris-ramon/douceur v0.2.0 // indirect
+ github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4 // indirect
+ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1 // indirect
+ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
+ github.com/emirpasic/gods v1.12.0 // indirect
+ github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021 // indirect
+ github.com/envoyproxy/protoc-gen-validate v0.1.0 // indirect
+ github.com/go-git/gcfg v1.5.0 // indirect
+ github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
+ github.com/golang/protobuf v1.5.2 // indirect
+ github.com/google/martian v2.1.0+incompatible // indirect
+ github.com/google/pprof v0.0.0-20211008130755-947d60d73cc0 // indirect
+ github.com/googleapis/gax-go/v2 v2.1.1 // indirect
+ github.com/gorilla/css v1.0.0 // indirect
+ github.com/hashicorp/errwrap v1.0.0 // indirect
+ github.com/hashicorp/go-multierror v1.1.0 // indirect
+ github.com/imdario/mergo v0.3.12 // indirect
+ github.com/jackc/chunkreader/v2 v2.0.1 // indirect
+ github.com/jackc/pgio v1.0.0 // indirect
+ github.com/jackc/pgpassfile v1.0.0 // indirect
+ github.com/jackc/pgproto3/v2 v2.2.0 // indirect
+ github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
+ github.com/jackc/pgtype v1.9.1 // indirect
+ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
+ github.com/jmespath/go-jmespath v0.4.0 // indirect
+ github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
+ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
+ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
+ github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
+ github.com/mitchellh/go-homedir v1.1.0 // indirect
+ github.com/prometheus/client_golang v1.7.1 // indirect
+ github.com/prometheus/client_model v0.2.0 // indirect
+ github.com/prometheus/common v0.10.0 // indirect
+ github.com/prometheus/procfs v0.6.0 // indirect
+ github.com/sergi/go-diff v1.1.0 // indirect
+ github.com/xanzy/ssh-agent v0.3.0 // indirect
+ github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da // indirect
+ go.uber.org/atomic v1.6.0 // indirect
+ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
+ golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
+ golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
+ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
+ google.golang.org/appengine v1.6.7 // indirect
+ gopkg.in/warnings.v0 v0.1.2 // indirect
+ gopkg.in/yaml.v2 v2.4.0 // indirect
+)
diff --git a/go.sum b/go.sum
index 461f1a8..bc187d5 100644
--- a/go.sum
+++ b/go.sum
@@ -207,7 +207,6 @@
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.3.0 h1:t/LhUZLVitR1Ow2YOnduCsavhwFUklBMoGVYUCqmCqk=
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
-github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
@@ -656,7 +655,6 @@
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
-github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo=
github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk=
github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8=
@@ -681,7 +679,6 @@
github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
-github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A=
github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA=
github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg=
diff --git a/internal/godoc/internal/doc/README b/internal/godoc/internal/doc/README
new file mode 100644
index 0000000..371f023
--- /dev/null
+++ b/internal/godoc/internal/doc/README
@@ -0,0 +1,5 @@
+This code was originally forked from Go 1.14.
+It was modified as needed for pkgsite.
+It was then reconciled with Go 1.17.3.
+Then it was reconciled with GO 1.18beta1.
+
diff --git a/internal/godoc/internal/doc/comment.go b/internal/godoc/internal/doc/comment.go
index 731f14f..9dbd6b8 100644
--- a/internal/godoc/internal/doc/comment.go
+++ b/internal/godoc/internal/doc/comment.go
@@ -238,26 +238,24 @@
// allow "'" for possessive "'s" only
for b := line; ; {
- i := strings.IndexRune(b, '\'')
- if i < 0 {
+ var ok bool
+ if _, b, ok = strings.Cut(b, "'"); !ok {
break
}
- if i+1 >= len(b) || b[i+1] != 's' || (i+2 < len(b) && b[i+2] != ' ') {
- return "" // not followed by "s "
+ if b != "s" && !strings.HasPrefix(b, "s ") {
+ return "" // ' not followed by s and then end-of-word
}
- b = b[i+2:]
}
// allow "." when followed by non-space
for b := line; ; {
- i := strings.IndexRune(b, '.')
- if i < 0 {
+ var ok bool
+ if _, b, ok = strings.Cut(b, "."); !ok {
break
}
- if i+1 >= len(b) || b[i+1] == ' ' {
+ if b == "" || strings.HasPrefix(b, " ") {
return "" // not followed by non-space
}
- b = b[i+1:]
}
return line
diff --git a/internal/godoc/internal/doc/doc.go b/internal/godoc/internal/doc/doc.go
index 5e74a58..21ae510 100644
--- a/internal/godoc/internal/doc/doc.go
+++ b/internal/godoc/internal/doc/doc.go
@@ -3,10 +3,6 @@
// license that can be found in the LICENSE file.
// Package doc extracts source code documentation from a Go AST.
-//
-// This code was originally forked from Go 1.14.
-// It was modified as needed for pkgsite.
-// It was then reconciled with Go 1.17.3.
package doc
import (
@@ -144,10 +140,12 @@
// NewFromFiles computes documentation for a package.
//
// The package is specified by a list of *ast.Files and corresponding
-// file set, which must not be nil. NewFromFiles does not skip files
-// based on build constraints, so it is the caller's responsibility to
-// provide only the files that are matched by the build context.
-// The import path of the package is specified by importPath.
+// file set, which must not be nil.
+// NewFromFiles uses all provided files when computing documentation,
+// so it is the caller's responsibility to provide only the files that
+// match the desired build context. "go/build".Context.MatchFile can
+// be used for determining whether a file matches a build context with
+// the desired GOOS and GOARCH values, and other build constraints.
//
// Examples found in _test.go files are associated with the corresponding
// type, function, method, or the package, based on their name.
@@ -160,7 +158,7 @@
// NewFromFiles takes ownership of the AST files and may edit them,
// unless the PreserveAST Mode bit is on.
//
-func NewFromFiles(fset *token.FileSet, files []*ast.File, importPath string, opts ...interface{}) (*Package, error) {
+func NewFromFiles(fset *token.FileSet, files []*ast.File, importPath string, opts ...any) (*Package, error) {
// Check for invalid API usage.
if fset == nil {
panic(fmt.Errorf("doc.NewFromFiles: no token.FileSet provided (fset == nil)"))
diff --git a/internal/godoc/internal/doc/doc_test.go b/internal/godoc/internal/doc/doc_test.go
index 5afd6dd..1dfa87d 100644
--- a/internal/godoc/internal/doc/doc_test.go
+++ b/internal/godoc/internal/doc/doc_test.go
@@ -38,7 +38,7 @@
return template.Must(t.ParseFiles(filepath.Join(dataDir, filename)))
}
-func nodeFmt(node interface{}, fset *token.FileSet) string {
+func nodeFmt(node any, fset *token.FileSet) string {
var buf bytes.Buffer
printer.Fprint(&buf, fset, node)
return strings.ReplaceAll(strings.TrimSpace(buf.String()), "\n", "\n\t")
diff --git a/internal/godoc/internal/doc/example.go b/internal/godoc/internal/doc/example.go
index 83aa51a..6dc1a53 100644
--- a/internal/godoc/internal/doc/example.go
+++ b/internal/godoc/internal/doc/example.go
@@ -45,13 +45,13 @@
// identifiers from other packages (or predeclared identifiers, such as
// "int") and the test file does not include a dot import.
// - The entire test file is the example: the file contains exactly one
-// example function, zero test or benchmark functions, and at least one
-// top-level function, type, variable, or constant declaration other
-// than the example function.
+// example function, zero test, fuzz test, or benchmark function, and at
+// least one top-level function, type, variable, or constant declaration
+// other than the example function.
func Examples(fset *token.FileSet, testFiles ...*ast.File) []*Example {
var list []*Example
for _, file := range testFiles {
- hasTests := false // file contains tests or benchmarks
+ hasTests := false // file contains tests, fuzz test, or benchmarks
numDecl := 0 // number of non-import declarations in the file
var flist []*Example
for _, decl := range file.Decls {
@@ -65,7 +65,7 @@
}
numDecl++
name := f.Name.Name
- if isTest(name, "Test") || isTest(name, "Benchmark") {
+ if isTest(name, "Test") || isTest(name, "Benchmark") || isTest(name, "Fuzz") {
hasTests = true
continue
}
@@ -134,9 +134,9 @@
return "", false, false // no suitable comment found
}
-// isTest tells whether name looks like a test, example, or benchmark.
-// It is a Test (say) if there is a character after Test that is not a
-// lower-case letter. (We don't want Testiness.)
+// isTest tells whether name looks like a test, example, fuzz test, or
+// benchmark. It is a Test (say) if there is a character after Test that is not
+// a lower-case letter. (We don't want Testiness.)
func isTest(name, prefix string) bool {
if !strings.HasPrefix(name, prefix) {
return false
diff --git a/internal/godoc/internal/doc/exports.go b/internal/godoc/internal/doc/exports.go
index 819c030..671c622 100644
--- a/internal/godoc/internal/doc/exports.go
+++ b/internal/godoc/internal/doc/exports.go
@@ -79,18 +79,15 @@
return false
}
-// removeErrorField removes anonymous fields named "error" from an interface.
-// This is called when "error" has been determined to be a local name,
-// not the predeclared type.
-//
-func removeErrorField(ityp *ast.InterfaceType) {
+// removeAnonymousField removes anonymous fields named name from an interface.
+func removeAnonymousField(name string, ityp *ast.InterfaceType) {
list := ityp.Methods.List // we know that ityp.Methods != nil
j := 0
for _, field := range list {
keepField := true
if n := len(field.Names); n == 0 {
// anonymous field
- if fname, _ := baseTypeName(field.Type); fname == "error" {
+ if fname, _ := baseTypeName(field.Type); fname == name {
keepField = false
}
}
@@ -119,16 +116,25 @@
for _, field := range list {
keepField := false
if n := len(field.Names); n == 0 {
- // anonymous field
+ // anonymous field or embedded type or union element
fname := r.recordAnonymousField(parent, field.Type)
- if token.IsExported(fname) {
- keepField = true
- } else if ityp != nil && fname == "error" {
- // possibly the predeclared error interface; keep
- // it for now but remember this interface so that
- // it can be fixed if error is also defined locally
- keepField = true
- r.remember(ityp)
+ if fname != "" {
+ if token.IsExported(fname) {
+ keepField = true
+ } else if ityp != nil && predeclaredTypes[fname] {
+ // possibly an embedded predeclared type; keep it for now but
+ // remember this interface so that it can be fixed if name is also
+ // defined locally
+ keepField = true
+ r.remember(fname, ityp)
+ }
+ } else {
+ // If we're operating on an interface, assume that this is an embedded
+ // type or union element.
+ //
+ // TODO(rfindley): consider traversing into approximation/unions
+ // elements to see if they are entirely unexported.
+ keepField = ityp != nil
}
} else {
field.Names = filterIdentList(field.Names)
@@ -172,6 +178,17 @@
// nothing to do
case *ast.ParenExpr:
r.filterType(nil, t.X)
+ case *ast.StarExpr: // possibly an embedded type literal
+ r.filterType(nil, t.X)
+ case *ast.UnaryExpr:
+ if t.Op == token.TILDE { // approximation element
+ r.filterType(nil, t.X)
+ }
+ case *ast.BinaryExpr:
+ if t.Op == token.OR { // union
+ r.filterType(nil, t.X)
+ r.filterType(nil, t.Y)
+ }
case *ast.ArrayType:
r.filterType(nil, t.Elt)
case *ast.StructType:
@@ -179,6 +196,7 @@
t.Incomplete = true
}
case *ast.FuncType:
+ r.filterParamList(t.TypeParams)
r.filterParamList(t.Params)
r.filterParamList(t.Results)
case *ast.InterfaceType:
@@ -219,12 +237,16 @@
}
}
case *ast.TypeSpec:
+ // Don't filter type parameters here, by analogy with function parameters
+ // which are not filtered for top-level function declarations.
if name := s.Name.Name; token.IsExported(name) {
r.filterType(r.lookupType(s.Name.Name), s.Type)
return true
- } else if name == "error" {
- // special case: remember that error is declared locally
- r.errorDecl = true
+ } else if IsPredeclared(name) {
+ if r.shadowedPredecl == nil {
+ r.shadowedPredecl = make(map[string]bool)
+ }
+ r.shadowedPredecl[name] = true
}
}
return false
diff --git a/internal/godoc/internal/doc/filter.go b/internal/godoc/internal/doc/filter.go
index a6f243f..9904da1 100644
--- a/internal/godoc/internal/doc/filter.go
+++ b/internal/godoc/internal/doc/filter.go
@@ -34,6 +34,8 @@
if f(v.Name.Name) {
return true
}
+ // We don't match ordinary parameters in filterFuncs, so by analogy don't
+ // match type parameters here.
switch t := v.Type.(type) {
case *ast.StructType:
if matchFields(t.Fields, f) {
diff --git a/internal/godoc/internal/doc/reader.go b/internal/godoc/internal/doc/reader.go
index 06dad81..20b1e3c 100644
--- a/internal/godoc/internal/doc/reader.go
+++ b/internal/godoc/internal/doc/reader.go
@@ -102,6 +102,10 @@
switch t := x.(type) {
case *ast.Ident:
return t.Name, false
+ case *ast.IndexExpr:
+ return baseTypeName(t.X)
+ case *ast.IndexListExpr:
+ return baseTypeName(t.X)
case *ast.SelectorExpr:
if _, ok := t.X.(*ast.Ident); ok {
// only possible for qualified type names;
@@ -113,7 +117,7 @@
case *ast.StarExpr:
return baseTypeName(t.X)
}
- return
+ return "", false
}
// An embeddedSet describes a set of embedded types.
@@ -164,9 +168,9 @@
types map[string]*namedType
funcs methodSet
- // support for package-local error type declarations
- errorDecl bool // if set, type "error" was declared locally
- fixlist []*ast.InterfaceType // list of interfaces containing anonymous field "error"
+ // support for package-local shadowing of predeclared types
+ shadowedPredecl map[string]bool
+ fixmap map[string][]*ast.InterfaceType
}
func (r *reader) isVisible(name string) bool {
@@ -225,8 +229,11 @@
r.doc += "\n" + text
}
-func (r *reader) remember(typ *ast.InterfaceType) {
- r.fixlist = append(r.fixlist, typ)
+func (r *reader) remember(predecl string, typ *ast.InterfaceType) {
+ if r.fixmap == nil {
+ r.fixmap = make(map[string][]*ast.InterfaceType)
+ }
+ r.fixmap[predecl] = append(r.fixmap[predecl], typ)
}
func specNames(specs []ast.Spec) []string {
@@ -419,6 +426,11 @@
factoryType = t.Elt
}
if n, imp := baseTypeName(factoryType); !imp && r.isVisible(n) && !r.isPredeclared(n) {
+ if lookupTypeParam(n, fun.Type.TypeParams) != nil {
+ // Issue #49477: don't associate fun with its type parameter result.
+ // A type parameter is not a defined type.
+ continue
+ }
if t := r.lookupType(n); t != nil {
typ = t
numResultTypes++
@@ -440,6 +452,22 @@
r.funcs.set(fun, r.mode&PreserveAST != 0)
}
+// lookupTypeParam searches for type parameters named name within the tparams
+// field list, returning the relevant identifier if found, or nil if not.
+func lookupTypeParam(name string, tparams *ast.FieldList) *ast.Ident {
+ if tparams == nil {
+ return nil
+ }
+ for _, field := range tparams.List {
+ for _, id := range field.Names {
+ if id.Name == name {
+ return id
+ }
+ }
+ }
+ return nil
+}
+
var (
noteMarker = `([A-Z][A-Z]+)\(([^)]+)\):?` // MARKER(uid), MARKER at least 2 chars, uid at least 1 char
noteMarkerRx = lazyregexp.New(`^[ \t]*` + noteMarker) // MARKER(uid) at text start
@@ -680,10 +708,11 @@
}
}
- // if error was declared locally, don't treat it as exported field anymore
- if r.errorDecl {
- for _, ityp := range r.fixlist {
- removeErrorField(ityp)
+ // For any predeclared names that are declared locally, don't treat them as
+ // exported fields anymore.
+ for predecl := range r.shadowedPredecl {
+ for _, ityp := range r.fixmap[predecl] {
+ removeAnonymousField(predecl, ityp)
}
}
}
@@ -870,6 +899,7 @@
}
var predeclaredTypes = map[string]bool{
+ "any": true,
"bool": true,
"byte": true,
"complex64": true,
diff --git a/internal/godoc/internal/doc/testdata/benchmark.go b/internal/godoc/internal/doc/testdata/benchmark.go
index 1d581f0..d27bf11 100644
--- a/internal/godoc/internal/doc/testdata/benchmark.go
+++ b/internal/godoc/internal/doc/testdata/benchmark.go
@@ -232,7 +232,7 @@
runtime.GOMAXPROCS(procs)
b := &B{
common: common{
- signal: make(chan interface{}),
+ signal: make(chan any),
},
benchmark: Benchmark,
}
@@ -285,7 +285,7 @@
func Benchmark(f func(b *B)) BenchmarkResult {
b := &B{
common: common{
- signal: make(chan interface{}),
+ signal: make(chan any),
},
benchmark: InternalBenchmark{"", f},
}
diff --git a/internal/godoc/internal/doc/testdata/generics.0.golden b/internal/godoc/internal/doc/testdata/generics.0.golden
new file mode 100644
index 0000000..91c874c
--- /dev/null
+++ b/internal/godoc/internal/doc/testdata/generics.0.golden
@@ -0,0 +1,76 @@
+// Package generics contains the new syntax supporting generic ...
+PACKAGE generics
+
+IMPORTPATH
+ testdata/generics
+
+FILENAMES
+ testdata/generics.go
+
+FUNCTIONS
+ // AnotherFunc has an implicit constraint interface. Neither type ...
+ func AnotherFunc[T ~struct{ f int }](_ struct{ f int })
+
+ // Func has an instantiated constraint.
+ func Func[T Constraint[string, Type[int]]]()
+
+ // Single is not a factory function.
+ func Single[T any]() *T
+
+ // Slice is not a factory function.
+ func Slice[T any]() []T
+
+
+TYPES
+ // AFuncType demonstrates filtering of parameters and type ...
+ type AFuncType[T ~struct{ f int }] func(_ struct {
+ // contains filtered or unexported fields
+ })
+
+ // Constraint is a constraint interface with two type parameters.
+ type Constraint[P, Q interface{ string | ~int | Type[int] }] interface {
+ ~int | ~byte | Type[string]
+ M() P
+ }
+
+ // NewEmbeddings demonstrates how we filter the new embedded ...
+ type NewEmbeddings interface {
+ string // should not be filtered
+
+ struct {
+ // contains filtered or unexported fields
+ }
+ ~struct {
+ // contains filtered or unexported fields
+ }
+ *struct {
+ // contains filtered or unexported fields
+ }
+ struct {
+ // contains filtered or unexported fields
+ } | ~struct {
+ // contains filtered or unexported fields
+ }
+ // contains filtered or unexported methods
+ }
+
+ // Parameterized types should be shown.
+ type Type[P any] struct {
+ Field P
+ }
+
+ // Variables with an instantiated type should be shown.
+ var X Type[int]
+
+ // Constructors for parameterized types should be shown.
+ func Constructor[lowerCase any]() Type[lowerCase]
+
+ // MethodA uses a different name for its receiver type parameter.
+ func (t Type[A]) MethodA(p A)
+
+ // MethodB has a blank receiver type parameter.
+ func (t Type[_]) MethodB()
+
+ // MethodC has a lower-case receiver type parameter.
+ func (t Type[c]) MethodC()
+
diff --git a/internal/godoc/internal/doc/testdata/generics.1.golden b/internal/godoc/internal/doc/testdata/generics.1.golden
new file mode 100644
index 0000000..923a4ce
--- /dev/null
+++ b/internal/godoc/internal/doc/testdata/generics.1.golden
@@ -0,0 +1,66 @@
+// Package generics contains the new syntax supporting generic ...
+PACKAGE generics
+
+IMPORTPATH
+ testdata/generics
+
+FILENAMES
+ testdata/generics.go
+
+FUNCTIONS
+ // AnotherFunc has an implicit constraint interface. Neither type ...
+ func AnotherFunc[T ~struct{ f int }](_ struct{ f int })
+
+ // Func has an instantiated constraint.
+ func Func[T Constraint[string, Type[int]]]()
+
+ // Single is not a factory function.
+ func Single[T any]() *T
+
+ // Slice is not a factory function.
+ func Slice[T any]() []T
+
+
+TYPES
+ // AFuncType demonstrates filtering of parameters and type ...
+ type AFuncType[T ~struct{ f int }] func(_ struct{ f int })
+
+ // Constraint is a constraint interface with two type parameters.
+ type Constraint[P, Q interface{ string | ~int | Type[int] }] interface {
+ ~int | ~byte | Type[string]
+ M() P
+ }
+
+ // NewEmbeddings demonstrates how we filter the new embedded ...
+ type NewEmbeddings interface {
+ string // should not be filtered
+ int16
+ struct{ f int }
+ ~struct{ f int }
+ *struct{ f int }
+ struct{ f int } | ~struct{ f int }
+ }
+
+ // Parameterized types should be shown.
+ type Type[P any] struct {
+ Field P
+ }
+
+ // Variables with an instantiated type should be shown.
+ var X Type[int]
+
+ // Constructors for parameterized types should be shown.
+ func Constructor[lowerCase any]() Type[lowerCase]
+
+ // MethodA uses a different name for its receiver type parameter.
+ func (t Type[A]) MethodA(p A)
+
+ // MethodB has a blank receiver type parameter.
+ func (t Type[_]) MethodB()
+
+ // MethodC has a lower-case receiver type parameter.
+ func (t Type[c]) MethodC()
+
+ // int16 shadows the predeclared type int16.
+ type int16 int
+
diff --git a/internal/godoc/internal/doc/testdata/generics.2.golden b/internal/godoc/internal/doc/testdata/generics.2.golden
new file mode 100644
index 0000000..91c874c
--- /dev/null
+++ b/internal/godoc/internal/doc/testdata/generics.2.golden
@@ -0,0 +1,76 @@
+// Package generics contains the new syntax supporting generic ...
+PACKAGE generics
+
+IMPORTPATH
+ testdata/generics
+
+FILENAMES
+ testdata/generics.go
+
+FUNCTIONS
+ // AnotherFunc has an implicit constraint interface. Neither type ...
+ func AnotherFunc[T ~struct{ f int }](_ struct{ f int })
+
+ // Func has an instantiated constraint.
+ func Func[T Constraint[string, Type[int]]]()
+
+ // Single is not a factory function.
+ func Single[T any]() *T
+
+ // Slice is not a factory function.
+ func Slice[T any]() []T
+
+
+TYPES
+ // AFuncType demonstrates filtering of parameters and type ...
+ type AFuncType[T ~struct{ f int }] func(_ struct {
+ // contains filtered or unexported fields
+ })
+
+ // Constraint is a constraint interface with two type parameters.
+ type Constraint[P, Q interface{ string | ~int | Type[int] }] interface {
+ ~int | ~byte | Type[string]
+ M() P
+ }
+
+ // NewEmbeddings demonstrates how we filter the new embedded ...
+ type NewEmbeddings interface {
+ string // should not be filtered
+
+ struct {
+ // contains filtered or unexported fields
+ }
+ ~struct {
+ // contains filtered or unexported fields
+ }
+ *struct {
+ // contains filtered or unexported fields
+ }
+ struct {
+ // contains filtered or unexported fields
+ } | ~struct {
+ // contains filtered or unexported fields
+ }
+ // contains filtered or unexported methods
+ }
+
+ // Parameterized types should be shown.
+ type Type[P any] struct {
+ Field P
+ }
+
+ // Variables with an instantiated type should be shown.
+ var X Type[int]
+
+ // Constructors for parameterized types should be shown.
+ func Constructor[lowerCase any]() Type[lowerCase]
+
+ // MethodA uses a different name for its receiver type parameter.
+ func (t Type[A]) MethodA(p A)
+
+ // MethodB has a blank receiver type parameter.
+ func (t Type[_]) MethodB()
+
+ // MethodC has a lower-case receiver type parameter.
+ func (t Type[c]) MethodC()
+
diff --git a/internal/godoc/internal/doc/testdata/generics.go b/internal/godoc/internal/doc/testdata/generics.go
new file mode 100644
index 0000000..ba7187e
--- /dev/null
+++ b/internal/godoc/internal/doc/testdata/generics.go
@@ -0,0 +1,74 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package generics contains the new syntax supporting generic programming in
+// Go.
+package generics
+
+// Variables with an instantiated type should be shown.
+var X Type[int]
+
+// Parameterized types should be shown.
+type Type[P any] struct {
+ Field P
+}
+
+// Constructors for parameterized types should be shown.
+func Constructor[lowerCase any]() Type[lowerCase] {
+ return Type[lowerCase]{}
+}
+
+// MethodA uses a different name for its receiver type parameter.
+func (t Type[A]) MethodA(p A) {}
+
+// MethodB has a blank receiver type parameter.
+func (t Type[_]) MethodB() {}
+
+// MethodC has a lower-case receiver type parameter.
+func (t Type[c]) MethodC() {}
+
+// Constraint is a constraint interface with two type parameters.
+type Constraint[P, Q interface{ string | ~int | Type[int] }] interface {
+ ~int | ~byte | Type[string]
+ M() P
+}
+
+// int16 shadows the predeclared type int16.
+type int16 int
+
+// NewEmbeddings demonstrates how we filter the new embedded elements.
+type NewEmbeddings interface {
+ string // should not be filtered
+ int16
+ struct{ f int }
+ ~struct{ f int }
+ *struct{ f int }
+ struct{ f int } | ~struct{ f int }
+}
+
+// Func has an instantiated constraint.
+func Func[T Constraint[string, Type[int]]]() {}
+
+// AnotherFunc has an implicit constraint interface.
+//
+// Neither type parameters nor regular parameters should be filtered.
+func AnotherFunc[T ~struct{ f int }](_ struct{ f int }) {}
+
+// AFuncType demonstrates filtering of parameters and type parameters. Here we
+// don't filter type parameters (to be consistent with function declarations),
+// but DO filter the RHS.
+type AFuncType[T ~struct{ f int }] func(_ struct{ f int })
+
+// See issue #49477: type parameters should not be interpreted as named types
+// for the purpose of determining whether a function is a factory function.
+
+// Slice is not a factory function.
+func Slice[T any]() []T {
+ return nil
+}
+
+// Single is not a factory function.
+func Single[T any]() *T {
+ return nil
+}
diff --git a/internal/godoc/internal/doc/testdata/testing.0.golden b/internal/godoc/internal/doc/testdata/testing.0.golden
index 83cf37c..61dac8b 100644
--- a/internal/godoc/internal/doc/testdata/testing.0.golden
+++ b/internal/godoc/internal/doc/testdata/testing.0.golden
@@ -46,10 +46,10 @@
}
// Error is equivalent to Log() followed by Fail().
- func (c *B) Error(args ...interface{})
+ func (c *B) Error(args ...any)
// Errorf is equivalent to Logf() followed by Fail().
- func (c *B) Errorf(format string, args ...interface{})
+ func (c *B) Errorf(format string, args ...any)
// Fail marks the function as having failed but continues ...
func (c *B) Fail()
@@ -61,16 +61,16 @@
func (c *B) Failed() bool
// Fatal is equivalent to Log() followed by FailNow().
- func (c *B) Fatal(args ...interface{})
+ func (c *B) Fatal(args ...any)
// Fatalf is equivalent to Logf() followed by FailNow().
- func (c *B) Fatalf(format string, args ...interface{})
+ func (c *B) Fatalf(format string, args ...any)
// Log formats its arguments using default formatting, analogous ...
- func (c *B) Log(args ...interface{})
+ func (c *B) Log(args ...any)
// Logf formats its arguments according to the format, analogous ...
- func (c *B) Logf(format string, args ...interface{})
+ func (c *B) Logf(format string, args ...any)
// ResetTimer sets the elapsed benchmark time to zero. It does not ...
func (b *B) ResetTimer()
@@ -125,10 +125,10 @@
}
// Error is equivalent to Log() followed by Fail().
- func (c *T) Error(args ...interface{})
+ func (c *T) Error(args ...any)
// Errorf is equivalent to Logf() followed by Fail().
- func (c *T) Errorf(format string, args ...interface{})
+ func (c *T) Errorf(format string, args ...any)
// Fail marks the function as having failed but continues ...
func (c *T) Fail()
@@ -140,16 +140,16 @@
func (c *T) Failed() bool
// Fatal is equivalent to Log() followed by FailNow().
- func (c *T) Fatal(args ...interface{})
+ func (c *T) Fatal(args ...any)
// Fatalf is equivalent to Logf() followed by FailNow().
- func (c *T) Fatalf(format string, args ...interface{})
+ func (c *T) Fatalf(format string, args ...any)
// Log formats its arguments using default formatting, analogous ...
- func (c *T) Log(args ...interface{})
+ func (c *T) Log(args ...any)
// Logf formats its arguments according to the format, analogous ...
- func (c *T) Logf(format string, args ...interface{})
+ func (c *T) Logf(format string, args ...any)
// Parallel signals that this test is to be run in parallel with ...
func (t *T) Parallel()
diff --git a/internal/godoc/internal/doc/testdata/testing.1.golden b/internal/godoc/internal/doc/testdata/testing.1.golden
index b9d1451..1655af1 100644
--- a/internal/godoc/internal/doc/testdata/testing.1.golden
+++ b/internal/godoc/internal/doc/testdata/testing.1.golden
@@ -119,10 +119,10 @@
}
// Error is equivalent to Log() followed by Fail().
- func (c *B) Error(args ...interface{})
+ func (c *B) Error(args ...any)
// Errorf is equivalent to Logf() followed by Fail().
- func (c *B) Errorf(format string, args ...interface{})
+ func (c *B) Errorf(format string, args ...any)
// Fail marks the function as having failed but continues ...
func (c *B) Fail()
@@ -134,16 +134,16 @@
func (c *B) Failed() bool
// Fatal is equivalent to Log() followed by FailNow().
- func (c *B) Fatal(args ...interface{})
+ func (c *B) Fatal(args ...any)
// Fatalf is equivalent to Logf() followed by FailNow().
- func (c *B) Fatalf(format string, args ...interface{})
+ func (c *B) Fatalf(format string, args ...any)
// Log formats its arguments using default formatting, analogous ...
- func (c *B) Log(args ...interface{})
+ func (c *B) Log(args ...any)
// Logf formats its arguments according to the format, analogous ...
- func (c *B) Logf(format string, args ...interface{})
+ func (c *B) Logf(format string, args ...any)
// ResetTimer sets the elapsed benchmark time to zero. It does not ...
func (b *B) ResetTimer()
@@ -221,10 +221,10 @@
}
// Error is equivalent to Log() followed by Fail().
- func (c *T) Error(args ...interface{})
+ func (c *T) Error(args ...any)
// Errorf is equivalent to Logf() followed by Fail().
- func (c *T) Errorf(format string, args ...interface{})
+ func (c *T) Errorf(format string, args ...any)
// Fail marks the function as having failed but continues ...
func (c *T) Fail()
@@ -236,16 +236,16 @@
func (c *T) Failed() bool
// Fatal is equivalent to Log() followed by FailNow().
- func (c *T) Fatal(args ...interface{})
+ func (c *T) Fatal(args ...any)
// Fatalf is equivalent to Logf() followed by FailNow().
- func (c *T) Fatalf(format string, args ...interface{})
+ func (c *T) Fatalf(format string, args ...any)
// Log formats its arguments using default formatting, analogous ...
- func (c *T) Log(args ...interface{})
+ func (c *T) Log(args ...any)
// Logf formats its arguments according to the format, analogous ...
- func (c *T) Logf(format string, args ...interface{})
+ func (c *T) Logf(format string, args ...any)
// Parallel signals that this test is to be run in parallel with ...
func (t *T) Parallel()
@@ -262,15 +262,15 @@
failed bool // Test or benchmark has failed.
start time.Time // Time test or benchmark started
duration time.Duration
- self interface{} // To be sent on signal channel when done.
- signal chan interface{} // Output for serial tests.
+ self any // To be sent on signal channel when done.
+ signal chan any // Output for serial tests.
}
// Error is equivalent to Log() followed by Fail().
- func (c *common) Error(args ...interface{})
+ func (c *common) Error(args ...any)
// Errorf is equivalent to Logf() followed by Fail().
- func (c *common) Errorf(format string, args ...interface{})
+ func (c *common) Errorf(format string, args ...any)
// Fail marks the function as having failed but continues ...
func (c *common) Fail()
@@ -282,16 +282,16 @@
func (c *common) Failed() bool
// Fatal is equivalent to Log() followed by FailNow().
- func (c *common) Fatal(args ...interface{})
+ func (c *common) Fatal(args ...any)
// Fatalf is equivalent to Logf() followed by FailNow().
- func (c *common) Fatalf(format string, args ...interface{})
+ func (c *common) Fatalf(format string, args ...any)
// Log formats its arguments using default formatting, analogous ...
- func (c *common) Log(args ...interface{})
+ func (c *common) Log(args ...any)
// Logf formats its arguments according to the format, analogous ...
- func (c *common) Logf(format string, args ...interface{})
+ func (c *common) Logf(format string, args ...any)
// log generates the output. It's always at the same stack depth.
func (c *common) log(s string)
diff --git a/internal/godoc/internal/doc/testdata/testing.2.golden b/internal/godoc/internal/doc/testdata/testing.2.golden
index 83cf37c..61dac8b 100644
--- a/internal/godoc/internal/doc/testdata/testing.2.golden
+++ b/internal/godoc/internal/doc/testdata/testing.2.golden
@@ -46,10 +46,10 @@
}
// Error is equivalent to Log() followed by Fail().
- func (c *B) Error(args ...interface{})
+ func (c *B) Error(args ...any)
// Errorf is equivalent to Logf() followed by Fail().
- func (c *B) Errorf(format string, args ...interface{})
+ func (c *B) Errorf(format string, args ...any)
// Fail marks the function as having failed but continues ...
func (c *B) Fail()
@@ -61,16 +61,16 @@
func (c *B) Failed() bool
// Fatal is equivalent to Log() followed by FailNow().
- func (c *B) Fatal(args ...interface{})
+ func (c *B) Fatal(args ...any)
// Fatalf is equivalent to Logf() followed by FailNow().
- func (c *B) Fatalf(format string, args ...interface{})
+ func (c *B) Fatalf(format string, args ...any)
// Log formats its arguments using default formatting, analogous ...
- func (c *B) Log(args ...interface{})
+ func (c *B) Log(args ...any)
// Logf formats its arguments according to the format, analogous ...
- func (c *B) Logf(format string, args ...interface{})
+ func (c *B) Logf(format string, args ...any)
// ResetTimer sets the elapsed benchmark time to zero. It does not ...
func (b *B) ResetTimer()
@@ -125,10 +125,10 @@
}
// Error is equivalent to Log() followed by Fail().
- func (c *T) Error(args ...interface{})
+ func (c *T) Error(args ...any)
// Errorf is equivalent to Logf() followed by Fail().
- func (c *T) Errorf(format string, args ...interface{})
+ func (c *T) Errorf(format string, args ...any)
// Fail marks the function as having failed but continues ...
func (c *T) Fail()
@@ -140,16 +140,16 @@
func (c *T) Failed() bool
// Fatal is equivalent to Log() followed by FailNow().
- func (c *T) Fatal(args ...interface{})
+ func (c *T) Fatal(args ...any)
// Fatalf is equivalent to Logf() followed by FailNow().
- func (c *T) Fatalf(format string, args ...interface{})
+ func (c *T) Fatalf(format string, args ...any)
// Log formats its arguments using default formatting, analogous ...
- func (c *T) Log(args ...interface{})
+ func (c *T) Log(args ...any)
// Logf formats its arguments according to the format, analogous ...
- func (c *T) Logf(format string, args ...interface{})
+ func (c *T) Logf(format string, args ...any)
// Parallel signals that this test is to be run in parallel with ...
func (t *T) Parallel()
diff --git a/internal/godoc/internal/doc/testdata/testing.go b/internal/godoc/internal/doc/testdata/testing.go
index 52810f7..80238df 100644
--- a/internal/godoc/internal/doc/testdata/testing.go
+++ b/internal/godoc/internal/doc/testdata/testing.go
@@ -77,8 +77,8 @@
failed bool // Test or benchmark has failed.
start time.Time // Time test or benchmark started
duration time.Duration
- self interface{} // To be sent on signal channel when done.
- signal chan interface{} // Output for serial tests.
+ self any // To be sent on signal channel when done.
+ signal chan any // Output for serial tests.
}
// Short reports whether the -test.short flag is set.
@@ -167,32 +167,32 @@
// Log formats its arguments using default formatting, analogous to Println(),
// and records the text in the error log.
-func (c *common) Log(args ...interface{}) { c.log(fmt.Sprintln(args...)) }
+func (c *common) Log(args ...any) { c.log(fmt.Sprintln(args...)) }
// Logf formats its arguments according to the format, analogous to Printf(),
// and records the text in the error log.
-func (c *common) Logf(format string, args ...interface{}) { c.log(fmt.Sprintf(format, args...)) }
+func (c *common) Logf(format string, args ...any) { c.log(fmt.Sprintf(format, args...)) }
// Error is equivalent to Log() followed by Fail().
-func (c *common) Error(args ...interface{}) {
+func (c *common) Error(args ...any) {
c.log(fmt.Sprintln(args...))
c.Fail()
}
// Errorf is equivalent to Logf() followed by Fail().
-func (c *common) Errorf(format string, args ...interface{}) {
+func (c *common) Errorf(format string, args ...any) {
c.log(fmt.Sprintf(format, args...))
c.Fail()
}
// Fatal is equivalent to Log() followed by FailNow().
-func (c *common) Fatal(args ...interface{}) {
+func (c *common) Fatal(args ...any) {
c.log(fmt.Sprintln(args...))
c.FailNow()
}
// Fatalf is equivalent to Logf() followed by FailNow().
-func (c *common) Fatalf(format string, args ...interface{}) {
+func (c *common) Fatalf(format string, args ...any) {
c.log(fmt.Sprintf(format, args...))
c.FailNow()
}
@@ -269,7 +269,7 @@
// If all tests pump to the same channel, a bug can occur where a test
// kicks off a goroutine that Fails, yet the test still delivers a completion signal,
// which skews the counting.
- var collector = make(chan interface{})
+ var collector = make(chan any)
numParallel := 0
startParallel := make(chan bool)
@@ -289,7 +289,7 @@
}
t := &T{
common: common{
- signal: make(chan interface{}),
+ signal: make(chan any),
},
name: testName,
startParallel: startParallel,