]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/doc: show variables of unexported types for -all
authorAgniva De Sarker <agnivade@yahoo.co.in>
Mon, 11 Nov 2019 19:22:57 +0000 (00:52 +0530)
committerAgniva De Sarker <agniva.quicksilver@gmail.com>
Tue, 12 Nov 2019 04:09:39 +0000 (04:09 +0000)
We use the typedValue map to prevent showing typed variables
and constants from appearing in the VARIABLES/CONSTANTS section
because they will be anyways shown in the TYPES section
for that type.

However, when a type is unexported, but the variable is exported,
then unconditionally setting it to true in the map suppresses it
from being shown in the VARIABLES section. Thus, we set the
variable or constant in the typedValue map only when
the type name is exported.

Fixes #31067

Change-Id: Id3ec4b313c9ea7e3ce6fe279680d56f65451719f
Reviewed-on: https://go-review.googlesource.com/c/go/+/206129
Run-TryBot: Agniva De Sarker <agniva.quicksilver@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 5c6ec8570330c39203ade42592b6ef763cc4a0a9..e425045ba5cebd30382844cacf14cd201b6c47e5 100644 (file)
@@ -176,6 +176,7 @@ var tests = []test{
                        `Comment about block of variables`,
                        `VarFive = 5`,
                        `var ExportedVariable = 1`,
+                       `var ExportedVarOfUnExported unexportedType`,
                        `var LongLine = newLongLine\(`,
                        `var MultiLineVar = map\[struct {`,
                        `FUNCTIONS`,
index fa31eba64bb29379f24b8d282282a2e3e858b8a1..bfbe765d3206f91287a2fe2471cc2468b175e5fa 100644 (file)
@@ -172,18 +172,18 @@ func parsePackage(writer io.Writer, pkg *build.Package, userPath string) *Packag
        constructor := make(map[*doc.Func]bool)
        for _, typ := range docPkg.Types {
                docPkg.Consts = append(docPkg.Consts, typ.Consts...)
-               for _, value := range typ.Consts {
-                       typedValue[value] = true
-               }
                docPkg.Vars = append(docPkg.Vars, typ.Vars...)
-               for _, value := range typ.Vars {
-                       typedValue[value] = true
-               }
                docPkg.Funcs = append(docPkg.Funcs, typ.Funcs...)
-               for _, fun := range typ.Funcs {
-                       // We don't count it as a constructor bound to the type
-                       // if the type itself is not exported.
-                       if isExported(typ.Name) {
+               if isExported(typ.Name) {
+                       for _, value := range typ.Consts {
+                               typedValue[value] = true
+                       }
+                       for _, value := range typ.Vars {
+                               typedValue[value] = true
+                       }
+                       for _, fun := range typ.Funcs {
+                               // We don't count it as a constructor bound to the type
+                               // if the type itself is not exported.
                                constructor[fun] = true
                        }
                }
index 759b7723a6c22d4dd01576393e0371cf8897fd0a..d695bdf1c5f6bbf10419f6ad2925d3251877fee5 100644 (file)
@@ -35,6 +35,8 @@ const (
 // Comment about exported variable.
 var ExportedVariable = 1
 
+var ExportedVarOfUnExported unexportedType
+
 // Comment about internal variable.
 var internalVariable = 2