Skip to content

Commit

Permalink
fix: ignore anonymous struct
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfogre committed Aug 19, 2020
1 parent 8d5afa2 commit fb58bf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 13 additions & 10 deletions internal/gtag/gtag.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,25 @@ func parseStructField(f *ast.File, name string) ([]*ast.Field, bool) {
var fields []*ast.Field
found := false

ast.Inspect(f, func(n ast.Node) bool {
ast.Inspect(f, func(node ast.Node) bool {
if found {
return false
}
switch t := n.(type) {
case *ast.TypeSpec:
if t, ok := node.(*ast.TypeSpec); ok {
if t.Name != nil && t.Name.Name == name {
return true
ast.Inspect(node, func(structNode ast.Node) bool {
if found {
return false
}
if t, ok := structNode.(*ast.StructType); ok {
found = true
fields = t.Fields.List
}
return !found
})
}
return false
case *ast.StructType:
fields = t.Fields.List
found = true
return false
}
return true
return !found
})

if !found {
Expand Down
6 changes: 6 additions & 0 deletions test/internal/regular/anonymous.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package regular

func _() {
_ = struct {
}{}
}

0 comments on commit fb58bf0

Please sign in to comment.