Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gaojingyu committed Feb 7, 2021
1 parent cfe4005 commit 5f32348
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/structcheck/structcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (v *visitor) typeAndFieldName(expr *ast.SelectorExpr) (types.Type, string,
if ptr, ok := recv.(*types.Pointer); ok {
recv = ptr.Elem()
}
for _, idx := range selection.Index()[:len(selection.Index())-1] {
recv = recv.Underlying().(*types.Struct).Field(idx).Type()
}

return recv, selection.Obj().Name(), true
}

Expand All @@ -100,6 +104,21 @@ func (v *visitor) assignStmt(node *ast.AssignStmt) {
}
}

func (v *visitor) getRealStruct(expr *ast.SelectorExpr, fieldName string) *ast.SelectorExpr {
tv := v.pkg.Types[expr.X]
if !tv.IsType() {
return expr
}

switch st := tv.Type.Underlying().(type) {
case *types.Struct:
obj, _, _ := types.LookupFieldOrMethod(st, false, v.pkg.Pkg, fieldName)
// return
_ = obj
}
return nil
}

func (v *visitor) compositeLiteral(node *ast.CompositeLit) {
t := v.pkg.Info.Types[node.Type].Type
for _, expr := range node.Elts {
Expand Down

0 comments on commit 5f32348

Please sign in to comment.