diff options
author | Joe Tsai <joetsai@digital-static.net> | 2016-08-01 20:04:25 -0700 |
---|---|---|
committer | Joe Tsai <thebrokentoaster@gmail.com> | 2016-08-02 03:24:48 +0000 |
commit | 6317c213c953d0879fe88593b4372f03d25f369b (patch) | |
tree | 3093266fa810c3cd1d1adc3fcc77af70d6499b94 | |
parent | f5758739a8f011c1d146a7736ab8f0d2834e1783 (diff) | |
download | go-6317c213c953d0879fe88593b4372f03d25f369b.tar.gz go-6317c213c953d0879fe88593b4372f03d25f369b.zip |
cmd/doc: ensure functions with unexported return values are shown
The commit in golang.org/cl/22354 groups constructors functions under
the type that they construct to. However, this caused a minor regression
where functions that had unexported return values were not being printed
at all. Thus, we forgo the grouping logic if the type the constructor falls
under is not going to be printed.
Fixes #16568
Change-Id: Idc14f5d03770282a519dc22187646bda676af612
Reviewed-on: https://go-review.googlesource.com/25369
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r-- | src/cmd/doc/doc_test.go | 8 | ||||
-rw-r--r-- | src/cmd/doc/pkg.go | 4 | ||||
-rw-r--r-- | src/cmd/doc/testdata/pkg.go | 3 |
3 files changed, 11 insertions, 4 deletions
diff --git a/src/cmd/doc/doc_test.go b/src/cmd/doc/doc_test.go index bfb9099dd2..453a3d53aa 100644 --- a/src/cmd/doc/doc_test.go +++ b/src/cmd/doc/doc_test.go @@ -61,6 +61,7 @@ var tests = []test{ `var ExportedVariable = 1`, // Simple variable. `var VarOne = 1`, // First entry in variable block. `func ExportedFunc\(a int\) bool`, // Function. + `func ReturnUnexported\(\) unexportedType`, // Function with unexported return type. `type ExportedType struct { ... }`, // Exported type. `const ExportedTypedConstant ExportedType = iota`, // Typed constant. `const ExportedTypedConstant_unexported unexportedType`, // Typed constant, exported for unexported type. @@ -89,9 +90,10 @@ var tests = []test{ "full package with u", []string{`-u`, p}, []string{ - `const ExportedConstant = 1`, // Simple constant. - `const internalConstant = 2`, // Internal constants. - `func internalFunc\(a int\) bool`, // Internal functions. + `const ExportedConstant = 1`, // Simple constant. + `const internalConstant = 2`, // Internal constants. + `func internalFunc\(a int\) bool`, // Internal functions. + `func ReturnUnexported\(\) unexportedType`, // Function with unexported return type. }, []string{ `Comment about exported constant`, // No comment for simple constant. diff --git a/src/cmd/doc/pkg.go b/src/cmd/doc/pkg.go index eec9f1e803..defddfd74a 100644 --- a/src/cmd/doc/pkg.go +++ b/src/cmd/doc/pkg.go @@ -317,7 +317,9 @@ func (pkg *Package) funcSummary(funcs []*doc.Func, showConstructors bool) { isConstructor = make(map[*doc.Func]bool) for _, typ := range pkg.doc.Types { for _, constructor := range typ.Funcs { - isConstructor[constructor] = true + if isExported(typ.Name) { + isConstructor[constructor] = true + } } } } diff --git a/src/cmd/doc/testdata/pkg.go b/src/cmd/doc/testdata/pkg.go index 9c5cf8f557..6a52ac2f65 100644 --- a/src/cmd/doc/testdata/pkg.go +++ b/src/cmd/doc/testdata/pkg.go @@ -123,3 +123,6 @@ const unexportedTypedConstant unexportedType = 1 // In a separate section to tes // For case matching. const CaseMatch = 1 const Casematch = 2 + +func ReturnUnexported() unexportedType { return 0 } +func ReturnExported() ExportedType { return ExportedType{} } |