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: factory methods of a type are not being shown with other methods #27928
Comments
You mean they are not being shown at all. |
There is something funky going on here. The Here is a sample reproducer - package main
import (
"fmt"
"go/doc"
"go/parser"
"go/token"
"log"
"os"
)
func main() {
include := func(info os.FileInfo) bool {
return true
}
fs := token.NewFileSet()
pkgs, err := parser.ParseDir(fs, "/usr/local/go/src/net/http", include, parser.ParseComments)
if err != nil {
log.Fatal(err)
}
astPkg := pkgs["http"]
docPkg := doc.New(astPkg, "net/http", doc.AllDecls)
for _, f := range docPkg.Funcs {
if f.Name == "NewRequest" {
fmt.Printf("got NewRequest: %v\n", f.Decl)
}
}
for _, t := range docPkg.Types {
if t.Name == "Request" {
fmt.Printf("got type Request %v\n", t.Funcs)
for _, f := range t.Funcs {
fmt.Printf("func %s\n", f.Name)
}
}
}
} Output with 1.11 -
Output with 1.10.3
So, it seems in 1.11, the factory methods detach themselves from the method and remain as a top-level But then how does godoc work ? https://tip.golang.org/pkg/net/http/#NewRequest Both are consumers of @griesemer - Any ideas here ? |
@agnivade It seems to me this is because of your change https://golang.org/cl/105575 (commit 6079536) which doesn't associate functions with more than one return value to the receiver type.
Haven't investigated godoc. Feel free to investigate. It seems to me that change https://golang.org/cl/105575 was too aggressive and that it probably shouldn't consider an error return when making the decision whether to associate a method or not. |
Yes, I had thought about that. But then |
Finally figured it out. This is an issue with the So we need to fine tune the logic a bit. But at least the mystery is solved on why |
Change https://golang.org/cl/141617 mentions this issue: |
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
Ran
go doc http.request
.What did you expect to see?
Snippet from
go1.10.4 doc http.request
's output:What did you see instead?
The same snippet with Go 1.11:
The text was updated successfully, but these errors were encountered: