Skip to content

Commit e40dea5

Browse files
committed
unused: don't track objects in other packages that use us
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. (cherry picked from commit 4ceb5b2)
1 parent 4970552 commit e40dea5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

unused/unused.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,13 @@ func isIrrelevant(obj types.Object) bool {
476476
}
477477

478478
func (g *graph) use(used, by types.Object) {
479-
if g.opts.ExportedIsUsed && used.Pkg() != g.pkg || used.Pkg() == nil {
480-
return
479+
if g.opts.ExportedIsUsed {
480+
if used.Pkg() != g.pkg || used.Pkg() == nil {
481+
return
482+
}
483+
if by != nil && by.Pkg() != g.pkg {
484+
return
485+
}
481486
}
482487

483488
if isIrrelevant(used) {

0 commit comments

Comments
 (0)