]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/doc: ensure functions with unexported return values are shown
authorJoe Tsai <joetsai@digital-static.net>
Tue, 2 Aug 2016 03:04:25 +0000 (20:04 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Tue, 2 Aug 2016 03:24:48 +0000 (03:24 +0000)
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>

src/cmd/doc/doc_test.go
src/cmd/doc/pkg.go
src/cmd/doc/testdata/pkg.go

index bfb9099dd2d6eceebbe8e5de80a4a7537b087e3f..453a3d53aa5481c4596f3829b42d5a2df8ed5425 100644 (file)
@@ -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.
index eec9f1e803e837d7655c83c3345ba778f2cdf524..defddfd74a6b9ccd2c2b34ce8e401afe33ca503b 100644 (file)
@@ -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
+                               }
                        }
                }
        }
index 9c5cf8f55764c3cc261324dd823766628a35bc18..6a52ac2f6540f11156e58114d811aa9b01641ec4 100644 (file)
@@ -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{} }