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 (
)
// 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
......
......@@ -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
)
......@@ -38,6 +38,12 @@ CONSTANTS
WideOpen = 0777
)
// Unexported constants counting from blank iota. See issue 9615.
const (
_ = iota
one = iota + 1
)
VARIABLES
//
......
......@@ -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
)
......@@ -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.
......
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