Skip to content

cmd/doc: does not generate docs for generic functions that return []T #48485

Description

@ahxxm

What version of Go are you using (go version)?

$ gotip version
`devel go1.18-a83a558 Mon Sep 20 00:13:47 2021 +0000`

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

linux amd64

What did you do?

I wrote a generic function(inside package), run gotip doc -all -c -u [package-name]

What did you expect to see?

expect to see the function signature in output, like func Intersection[T comparable](slices... []T) []T

What did you see instead?

functions that return []T are not printed, others like func Some[T any](slice []T, pred func(T) bool) bool are printed

I tried dig into the doc generator, found that

  • these functions are now considered to be factory functions of T, their associations go typ.funcs.set branch instead of r.funcs.set
  • cleanupTypes() deleted T from r.types because it has no definition
  • then T is not included in docPkg.Types, thus no results are printed

with following immature hack diff those functions will be printed:

@@ -429,8 +436,9 @@ func (r *reader) readFunc(fun *ast.FuncDecl) {
                 }
                 // If there is exactly one result type,
                 // associate the function with that type.
-                if numResultTypes == 1 {
+                if numResultTypes == 1 && typ.decl != nil {

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions