]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/doc: don't drop const/var block if first entry is unexported
authorRob Pike <r@golang.org>
Fri, 18 Sep 2015 21:53:33 +0000 (14:53 -0700)
committerRob Pike <r@golang.org>
Mon, 21 Sep 2015 16:42:09 +0000 (16:42 +0000)
The code assumed that if the first entry was unexported, all the
entries were. The fix is simple: delete a bunch of code.

Fixes #12286.

Change-Id: Icb09274e99ce97df4d8bddbe59d17a5c0622e4c6
Reviewed-on: https://go-review.googlesource.com/14780
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/cmd/doc/doc_test.go
src/cmd/doc/pkg.go
src/cmd/doc/testdata/pkg.go

index b97cc7688db7b081792063de2d5d40819320a2b4..b3b0f606cd1312d3a295ae1167eda5d5faac0e2a 100644 (file)
@@ -54,6 +54,7 @@ var tests = []test{
                        `Package comment`,
                        `const ExportedConstant = 1`,                            // Simple constant.
                        `const ConstOne = 1`,                                    // First entry in constant block.
+                       `const ConstFive ...`,                                   // From block starting with unexported constant.
                        `var ExportedVariable = 1`,                              // Simple variable.
                        `var VarOne = 1`,                                        // First entry in variable block.
                        `func ExportedFunc\(a int\) bool`,                       // Function.
@@ -73,6 +74,7 @@ var tests = []test{
                        `Comment before VarOne`,             // No comment for first entry in variable block.
                        `ConstTwo = 2`,                      // No second entry in constant block.
                        `VarTwo = 2`,                        // No second entry in variable block.
+                       `VarFive = 5`,                       // From block starting with unexported variable.
                        `type unexportedType`,               // No unexported type.
                        `unexportedTypedConstant`,           // No unexported typed constant.
                        `Field`,                             // No fields.
index daa22e459dcefdfbf81a202041257d2ee41465cc..3e97fd3461d7fef7700bde04a90e3504798b6db5 100644 (file)
@@ -257,18 +257,7 @@ func (pkg *Package) packageClause(checkUserPath bool) {
 // valueSummary prints a one-line summary for each set of values and constants.
 func (pkg *Package) valueSummary(values []*doc.Value) {
        for _, value := range values {
-               // Only print first item in spec, show ... to stand for the rest.
-               spec := value.Decl.Specs[0].(*ast.ValueSpec) // Must succeed.
-               exported := true
-               for _, name := range spec.Names {
-                       if !isExported(name.Name) {
-                               exported = false
-                               break
-                       }
-               }
-               if exported {
-                       pkg.oneLineValueGenDecl(value.Decl)
-               }
+               pkg.oneLineValueGenDecl(value.Decl)
        }
 }
 
index ebefb50b2a100a7f9da470e864e0ddba4a7129ab..0f06651d6bc16508dd9bd35a581c6317d4ecd84a 100644 (file)
@@ -21,6 +21,13 @@ const (
        constThree = 3 // Comment on line with constThree.
 )
 
+// Const block where first entry is unexported.
+const (
+       constFour = iota
+       ConstFive
+       ConstSix
+)
+
 // Variables
 
 // Comment about exported variable.
@@ -37,6 +44,13 @@ var (
        varThree = 3 // Comment on line with varThree.
 )
 
+// Var block where first entry is unexported.
+var (
+       varFour = 4
+       VarFive = 5
+       varSix  = 6
+)
+
 // Comment about exported function.
 func ExportedFunc(a int) bool