mirror of
https://github.com/golang/go
synced 2024-11-26 08:17:59 -07:00
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
This commit is contained in:
parent
7539c8501d
commit
22ec539920
@ -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) {
|
func (doc *docReader) addType(decl *ast.GenDecl) {
|
||||||
typ := decl.Specs[0].(*ast.TypeSpec);
|
spec := decl.Specs[0].(*ast.TypeSpec);
|
||||||
name := typ.Name.Value;
|
name := spec.Name.Value;
|
||||||
if _, found := doc.types[name]; !found {
|
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
|
||||||
|
}
|
||||||
tdoc := &typeDoc{decl, make(map[string] *ast.FuncDecl), make(map[string] *ast.FuncDecl)};
|
tdoc := &typeDoc{decl, make(map[string] *ast.FuncDecl), make(map[string] *ast.FuncDecl)};
|
||||||
doc.types[name] = tdoc;
|
doc.types[name] = tdoc;
|
||||||
}
|
|
||||||
// If the type was found it may have been added as a forward
|
|
||||||
// declaration before, or this is a forward-declaration.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user