Commit aafb5bca authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder Committed by Robert Griesemer

go/doc: don't treat _ consts as exported

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