mirror of
https://github.com/golang/go
synced 2024-11-18 16:24:42 -07:00
go/doc: hide methods on locally-declared predeclared types
Currently if you declare a type overwriting a predeclared type and export methods on it they will be exposed in godoc, even though the type itself is not exported. This corrects that by making all methods on these types hidden, since that's the expected output. Fixes #9860 Change-Id: I14037bdcef1b4bbefcf299a143bac8bf363718e0 Reviewed-on: https://go-review.googlesource.com/20610 Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
eee727d085
commit
5fd6bb4c14
@ -645,7 +645,9 @@ func (r *reader) computeMethodSets() {
|
||||
func (r *reader) cleanupTypes() {
|
||||
for _, t := range r.types {
|
||||
visible := r.isVisible(t.name)
|
||||
if t.decl == nil && (predeclaredTypes[t.name] || visible && (t.isEmbedded || r.hasDotImp)) {
|
||||
predeclared := predeclaredTypes[t.name]
|
||||
|
||||
if t.decl == nil && (predeclared || visible && (t.isEmbedded || r.hasDotImp)) {
|
||||
// t.name is a predeclared type (and was not redeclared in this package),
|
||||
// or it was embedded somewhere but its declaration is missing (because
|
||||
// the AST is incomplete), or we have a dot-import (and all bets are off):
|
||||
@ -660,6 +662,7 @@ func (r *reader) cleanupTypes() {
|
||||
r.funcs[name] = f
|
||||
}
|
||||
// 3) move methods
|
||||
if !predeclared {
|
||||
for name, m := range t.methods {
|
||||
// don't overwrite functions with the same name - drop them
|
||||
if _, found := r.funcs[name]; !found {
|
||||
@ -667,6 +670,7 @@ func (r *reader) cleanupTypes() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove types w/o declaration or which are not visible
|
||||
if t.decl == nil || !visible {
|
||||
delete(r.types, t.name)
|
||||
|
8
src/go/doc/testdata/predeclared.0.golden
vendored
Normal file
8
src/go/doc/testdata/predeclared.0.golden
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
// Package predeclared is a go/doc test for handling of exported ...
|
||||
PACKAGE predeclared
|
||||
|
||||
IMPORTPATH
|
||||
testdata/predeclared
|
||||
|
||||
FILENAMES
|
||||
testdata/predeclared.go
|
22
src/go/doc/testdata/predeclared.1.golden
vendored
Normal file
22
src/go/doc/testdata/predeclared.1.golden
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// Package predeclared is a go/doc test for handling of exported ...
|
||||
PACKAGE predeclared
|
||||
|
||||
IMPORTPATH
|
||||
testdata/predeclared
|
||||
|
||||
FILENAMES
|
||||
testdata/predeclared.go
|
||||
|
||||
TYPES
|
||||
//
|
||||
type bool int
|
||||
|
||||
// Must not be visible.
|
||||
func (b bool) String() string
|
||||
|
||||
//
|
||||
type error struct{}
|
||||
|
||||
// Must not be visible.
|
||||
func (e error) Error() string
|
||||
|
8
src/go/doc/testdata/predeclared.2.golden
vendored
Normal file
8
src/go/doc/testdata/predeclared.2.golden
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
// Package predeclared is a go/doc test for handling of exported ...
|
||||
PACKAGE predeclared
|
||||
|
||||
IMPORTPATH
|
||||
testdata/predeclared
|
||||
|
||||
FILENAMES
|
||||
testdata/predeclared.go
|
22
src/go/doc/testdata/predeclared.go
vendored
Normal file
22
src/go/doc/testdata/predeclared.go
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package predeclared is a go/doc test for handling of
|
||||
// exported methods on locally-defined predeclared types.
|
||||
// See issue 9860.
|
||||
package predeclared
|
||||
|
||||
type error struct{}
|
||||
|
||||
// Must not be visible.
|
||||
func (e error) Error() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
type bool int
|
||||
|
||||
// Must not be visible.
|
||||
func (b bool) String() string {
|
||||
return ""
|
||||
}
|
Loading…
Reference in New Issue
Block a user