aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/doc
diff options
context:
space:
mode:
authorAgniva De Sarker <agnivade@yahoo.co.in>2019-11-12 00:52:57 +0530
committerAgniva De Sarker <agniva.quicksilver@gmail.com>2019-11-12 04:09:39 +0000
commit72e043e48bf47ce03229b011d2468f46081055ad (patch)
tree0b9f91a2ead94f07214a9997200fbf79df7b95a8 /src/cmd/doc
parentc2edcf4b1253fdebc13df8a25979904c3ef01c66 (diff)
downloadgo-72e043e48bf47ce03229b011d2468f46081055ad.tar.gz
go-72e043e48bf47ce03229b011d2468f46081055ad.zip
cmd/doc: show variables of unexported types for -all
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>
Diffstat (limited to 'src/cmd/doc')
-rw-r--r--src/cmd/doc/doc_test.go1
-rw-r--r--src/cmd/doc/pkg.go20
-rw-r--r--src/cmd/doc/testdata/pkg.go2
3 files changed, 13 insertions, 10 deletions
diff --git a/src/cmd/doc/doc_test.go b/src/cmd/doc/doc_test.go
index 5c6ec85703..e425045ba5 100644
--- a/src/cmd/doc/doc_test.go
+++ b/src/cmd/doc/doc_test.go
@@ -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`,
diff --git a/src/cmd/doc/pkg.go b/src/cmd/doc/pkg.go
index fa31eba64b..bfbe765d32 100644
--- a/src/cmd/doc/pkg.go
+++ b/src/cmd/doc/pkg.go
@@ -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
}
}
diff --git a/src/cmd/doc/testdata/pkg.go b/src/cmd/doc/testdata/pkg.go
index 759b7723a6..d695bdf1c5 100644
--- a/src/cmd/doc/testdata/pkg.go
+++ b/src/cmd/doc/testdata/pkg.go
@@ -35,6 +35,8 @@ const (
// Comment about exported variable.
var ExportedVariable = 1
+var ExportedVarOfUnExported unexportedType
+
// Comment about internal variable.
var internalVariable = 2