diff options
author | Robert Griesemer <gri@golang.org> | 2009-07-31 18:40:11 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2009-07-31 18:40:11 -0700 |
commit | ef75aaa6310b19cf2dbc7bc5ad9cb7c186a81767 (patch) | |
tree | 5dedadfc1db1d37da7ab9de015a96a060abbbf17 /src/pkg/go/doc | |
parent | f5f8035bb0bcfcb7cfe52c34bf1947d5051f7bef (diff) | |
download | golang-ef75aaa6310b19cf2dbc7bc5ad9cb7c186a81767.tar.gz |
fix long-standing bug in doc reader:
- replace forward-declared types with complete
declaration when it is found
R=rsc
DELTA=23 (15 added, 0 deleted, 8 changed)
OCL=32618
CL=32618
Diffstat (limited to 'src/pkg/go/doc')
-rw-r--r-- | src/pkg/go/doc/doc.go | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/pkg/go/doc/doc.go b/src/pkg/go/doc/doc.go index 287677aa0..634bd0ce9 100644 --- a/src/pkg/go/doc/doc.go +++ b/src/pkg/go/doc/doc.go @@ -72,15 +72,30 @@ func (doc *docReader) lookupTypeDoc(typ ast.Expr) *typeDoc { } +func isForwardDecl(typ ast.Expr) bool { + switch t := typ.(type) { + case *ast.StructType: + return t.Fields == nil; + case *ast.InterfaceType: + return t.Methods == nil; + } + return false; +} + + func (doc *docReader) addType(decl *ast.GenDecl) { - typ := decl.Specs[0].(*ast.TypeSpec); - name := typ.Name.Value; - if _, found := doc.types[name]; !found { - tdoc := &typeDoc{decl, make(map[string] *ast.FuncDecl), make(map[string] *ast.FuncDecl)}; - doc.types[name] = tdoc; + spec := decl.Specs[0].(*ast.TypeSpec); + name := spec.Name.Value; + if tdoc, found := doc.types[name]; found { + if !isForwardDecl(tdoc.decl.Specs[0].(*ast.TypeSpec).Type) || isForwardDecl(spec.Type) { + // existing type was not a forward-declaration or the + // new type is a forward declaration - leave it alone + return; + } + // replace existing type } - // If the type was found it may have been added as a forward - // declaration before, or this is a forward-declaration. + tdoc := &typeDoc{decl, make(map[string] *ast.FuncDecl), make(map[string] *ast.FuncDecl)}; + doc.types[name] = tdoc; } |