Skip to content

Commit

Permalink
fix(go_indexer): visit anon members in struct type (#5734)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Jul 11, 2023
1 parent 2fcdd09 commit 8bec728
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kythe/go/indexer/emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ func (pi *PackageInfo) Emit(ctx context.Context, sink Sink, opts *EmitOptions) e
e.visitIndexExpr(n, stack)
case *ast.IndexListExpr:
e.visitIndexListExpr(n, stack)
case *ast.ArrayType:
e.visitArrayType(n, stack)
}
return true
}), file)
Expand Down Expand Up @@ -830,6 +832,11 @@ func (e *emitter) visitIndexListExpr(expr *ast.IndexListExpr, stack stackFunc) {
}
}

// visitArrayType handles references to array types.
func (e *emitter) visitArrayType(expr *ast.ArrayType, stack stackFunc) {
e.emitAnonMembers(expr.Elt)
}

// emitPosRef emits an anchor spanning loc, pointing to obj.
func (e *emitter) emitPosRef(loc ast.Node, obj types.Object, kind string) {
target := e.pi.ObjectVName(obj)
Expand Down
22 changes: 22 additions & 0 deletions kythe/go/indexer/testdata/structinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,25 @@ func realNames() {
{nick: "kyle"},
}
}

func anonSlice() {
type S = struct{ N string }
_ = []struct {
//- @F defines/binding F
F string

A []S
}{
{
//- @F ref/writes F
F: "",

//- @N defines/binding N
A: []struct{ N string }{
// TODO: tie anon field back to original def
//- @N ref/writes N
{N: ""},
},
},
}
}

0 comments on commit 8bec728

Please sign in to comment.