]> Cypherpunks repositories - gostls13.git/commitdiff
go/doc: don't treat _ consts as exported
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 3 Feb 2015 23:12:26 +0000 (15:12 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 4 Feb 2015 00:25:54 +0000 (00:25 +0000)
golang.org/cl/144110044 made _ consts treated
as exported as a small, safe fix for #5397.
It also introduced issue #9615.

golang.org/cl/2091 then fixed the underlying issue,
which was missing type information when the type
was specified only for _.

This cl reverts the original fix.

Fixes #9615.

Change-Id: I4815ad8292bb5bec18beb8c131b48949d9af8876
Reviewed-on: https://go-review.googlesource.com/3832
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/doc/exports.go
src/go/doc/testdata/blank.0.golden
src/go/doc/testdata/blank.1.golden
src/go/doc/testdata/blank.2.golden
src/go/doc/testdata/blank.go

index 06789bc1081289b7c2bfcbeebe9cf3e7b279d8b4..6aa38f15287e05415b515834189c5bf8e0bbd155 100644 (file)
@@ -12,13 +12,12 @@ import (
 )
 
 // filterIdentList removes unexported names from list in place
-// and returns the resulting list. If blankOk is set, blank
-// identifiers are considered exported names.
+// and returns the resulting list.
 //
-func filterIdentList(list []*ast.Ident, blankOk bool) []*ast.Ident {
+func filterIdentList(list []*ast.Ident) []*ast.Ident {
        j := 0
        for _, x := range list {
-               if ast.IsExported(x.Name) || (blankOk && x.Name == "_") {
+               if ast.IsExported(x.Name) {
                        list[j] = x
                        j++
                }
@@ -26,11 +25,11 @@ func filterIdentList(list []*ast.Ident, blankOk bool) []*ast.Ident {
        return list[0:j]
 }
 
-// hasExportedOrBlankName reports whether list contains any exported or blank names.
+// hasExportedName reports whether list contains any exported names.
 //
-func hasExportedOrBlankName(list []*ast.Ident) bool {
+func hasExportedName(list []*ast.Ident) bool {
        for _, x := range list {
-               if x.IsExported() || x.Name == "_" {
+               if x.IsExported() {
                        return true
                }
        }
@@ -89,7 +88,7 @@ func (r *reader) filterFieldList(parent *namedType, fields *ast.FieldList, ityp
                                r.remember(ityp)
                        }
                } else {
-                       field.Names = filterIdentList(field.Names, false)
+                       field.Names = filterIdentList(field.Names)
                        if len(field.Names) < n {
                                removedFields = true
                        }
@@ -157,9 +156,7 @@ func (r *reader) filterSpec(spec ast.Spec, tok token.Token) bool {
                // always keep imports so we can collect them
                return true
        case *ast.ValueSpec:
-               // special case: consider blank constants as exported
-               // (work-around for issue 5397)
-               s.Names = filterIdentList(s.Names, tok == token.CONST)
+               s.Names = filterIdentList(s.Names)
                if len(s.Names) > 0 {
                        r.filterType(nil, s.Type)
                        return true
@@ -207,9 +204,8 @@ func (r *reader) filterSpecList(list []ast.Spec, tok token.Token) []ast.Spec {
                                // provide current spec with an explicit type
                                spec.Type = copyConstType(prevType, spec.Pos())
                        }
-                       if hasExportedOrBlankName(spec.Names) {
-                               // both exported and blank names are preserved
-                               // so there's no need to propagate the type
+                       if hasExportedName(spec.Names) {
+                               // exported names are preserved so there's no need to propagate the type
                                prevType = nil
                        } else {
                                prevType = spec.Type
index 5f34038426b9fd933229abf5b90ed083c065ca64..c2987cf140ec4dfa0a9e78e647b698f52c38f75c 100644 (file)
@@ -30,8 +30,7 @@ CONSTANTS
 
        // Package constants. 
        const (
-               _       int     = iota
-               I1
+               I1      int
                I2
        )
 
@@ -50,8 +49,7 @@ TYPES
 
        // T constants counting from a blank constant. 
        const (
-               _       T       = iota
-               T1
+               T1      T
                T2
        )
 
index af5328fbb6904aa5eea872e14ced6baeedd3cb20..ee5054a4ed616f73169eadfe5741a06012d9b242 100644 (file)
@@ -38,6 +38,12 @@ CONSTANTS
                WideOpen                        = 0777
        )
 
+       // Unexported constants counting from blank iota. See issue 9615. 
+       const (
+               _       = iota
+               one     = iota + 1
+       )
+
 
 VARIABLES
        // 
index 5f34038426b9fd933229abf5b90ed083c065ca64..c2987cf140ec4dfa0a9e78e647b698f52c38f75c 100644 (file)
@@ -30,8 +30,7 @@ CONSTANTS
 
        // Package constants. 
        const (
-               _       int     = iota
-               I1
+               I1      int
                I2
        )
 
@@ -50,8 +49,7 @@ TYPES
 
        // T constants counting from a blank constant. 
        const (
-               _       T       = iota
-               T1
+               T1      T
                T2
        )
 
index 83e42ed39fa9cd509b06b95408d6dbcc671b7a8f..419a78f7d5116f0779f3f9d2381fe771ba3cbac7 100644 (file)
@@ -44,6 +44,13 @@ const (
        I2
 )
 
+// Unexported constants counting from blank iota.
+// See issue 9615.
+const (
+       _   = iota
+       one = iota + 1
+)
+
 // Blanks not in doc output:
 
 // S has a padding field.