Skip to content

Commit

Permalink
unused: don't track objects in other packages that use us
Browse files Browse the repository at this point in the history
When converting between two struct types, the fields use each other.
However, we mustn't track the fields in a struct type from another
package, as they should always be considered used, and we may end up
creating nodes for them without ever recording uses.

The old implementation of unused behaved correctly; we accidentally
dropped a check.

Closes gh-1360.
  • Loading branch information
dominikh committed Feb 3, 2023
1 parent 801a056 commit 4ceb5b2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions unused/unused.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,13 @@ func isIrrelevant(obj types.Object) bool {
}

func (g *graph) use(used, by types.Object) {
if g.opts.ExportedIsUsed && used.Pkg() != g.pkg || used.Pkg() == nil {
return
if g.opts.ExportedIsUsed {
if used.Pkg() != g.pkg || used.Pkg() == nil {
return
}
if by != nil && by.Pkg() != g.pkg {
return
}
}

if isIrrelevant(used) {
Expand Down

0 comments on commit 4ceb5b2

Please sign in to comment.