Skip to content

Commit 6317c21

Browse files
committed
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 <[email protected]> Reviewed-by: Rob Pike <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent f575873 commit 6317c21

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/cmd/doc/doc_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ var tests = []test{
6161
`var ExportedVariable = 1`, // Simple variable.
6262
`var VarOne = 1`, // First entry in variable block.
6363
`func ExportedFunc\(a int\) bool`, // Function.
64+
`func ReturnUnexported\(\) unexportedType`, // Function with unexported return type.
6465
`type ExportedType struct { ... }`, // Exported type.
6566
`const ExportedTypedConstant ExportedType = iota`, // Typed constant.
6667
`const ExportedTypedConstant_unexported unexportedType`, // Typed constant, exported for unexported type.
@@ -89,9 +90,10 @@ var tests = []test{
8990
"full package with u",
9091
[]string{`-u`, p},
9192
[]string{
92-
`const ExportedConstant = 1`, // Simple constant.
93-
`const internalConstant = 2`, // Internal constants.
94-
`func internalFunc\(a int\) bool`, // Internal functions.
93+
`const ExportedConstant = 1`, // Simple constant.
94+
`const internalConstant = 2`, // Internal constants.
95+
`func internalFunc\(a int\) bool`, // Internal functions.
96+
`func ReturnUnexported\(\) unexportedType`, // Function with unexported return type.
9597
},
9698
[]string{
9799
`Comment about exported constant`, // No comment for simple constant.

src/cmd/doc/pkg.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ func (pkg *Package) funcSummary(funcs []*doc.Func, showConstructors bool) {
317317
isConstructor = make(map[*doc.Func]bool)
318318
for _, typ := range pkg.doc.Types {
319319
for _, constructor := range typ.Funcs {
320-
isConstructor[constructor] = true
320+
if isExported(typ.Name) {
321+
isConstructor[constructor] = true
322+
}
321323
}
322324
}
323325
}

src/cmd/doc/testdata/pkg.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,6 @@ const unexportedTypedConstant unexportedType = 1 // In a separate section to tes
123123
// For case matching.
124124
const CaseMatch = 1
125125
const Casematch = 2
126+
127+
func ReturnUnexported() unexportedType { return 0 }
128+
func ReturnExported() ExportedType { return ExportedType{} }

0 commit comments

Comments
 (0)