Commit 72e043e4 authored by Agniva De Sarker's avatar Agniva De Sarker Committed by Agniva De Sarker

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: default avatarRob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c2edcf4b
......@@ -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`,
......
......@@ -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...)
docPkg.Vars = append(docPkg.Vars, typ.Vars...)
docPkg.Funcs = append(docPkg.Funcs, typ.Funcs...)
if isExported(typ.Name) {
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) {
constructor[fun] = true
}
}
......
......@@ -35,6 +35,8 @@ const (
// Comment about exported variable.
var ExportedVariable = 1
var ExportedVarOfUnExported unexportedType
// Comment about internal variable.
var internalVariable = 2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment