Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ahxxm opened this issue Sep 20, 2021 · 6 comments
Closed

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

ahxxm opened this issue Sep 20, 2021 · 6 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@ahxxm
Copy link

ahxxm commented Sep 20, 2021

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 {
@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 20, 2021
@dr2chase
Copy link
Contributor

@mvdan, @mdempsky this seems to have your name on it, seems relevant to getting generics into 1.18.

@mvdan
Copy link
Member

mvdan commented Sep 22, 2021

With the suggested change, is the result that the generic function isn't considered a constructor, and is thus rendered as a regular top-level function?

That seems fine to me - if it returns a generic slice type, it's not like we can attach it to any specific type.

Want to send a PR? It should include a test.

@ahxxm
Copy link
Author

ahxxm commented Sep 27, 2021

@mvdan yup, they are rendered as regular top-level functions

I submitted a PR, is this test case ok..?

@gopherbot
Copy link

Change https://golang.org/cl/352389 mentions this issue: cmd/doc: generate docs for generic functions that return []T

@mvdan
Copy link
Member

mvdan commented Sep 27, 2021

Thanks! I've left you a review on Gerrit. See https://github.com/golang/go/wiki/GerritBot.

@jba
Copy link
Contributor

jba commented Mar 4, 2022

Duplicate of #49477, which was fixed.

@jba jba closed this as completed Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants