Skip to content

Commit

Permalink
unused: we may still encounter interesting objects from export data
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikh committed May 3, 2019
1 parent bdce9a7 commit 2f699b8
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions unused/unused.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ func (c *Checker) Result() []types.Object {
continue
}
position := c.fset.PositionFor(v.Pos(), false)
position.Column = 1
position.Offset = 0
if _, ok := c.seen[position]; !ok {
out2 = append(out2, v)
}
Expand Down Expand Up @@ -669,13 +671,27 @@ func (c *Checker) results() []types.Object {
report := func(node *Node) {
if node.seen {
var pos token.Pos
switch obj := node.obj.(type) {
case types.Object:
if obj, ok := node.obj.(types.Object); ok {
pos = obj.Pos()
}

if pos != 0 {
if pos != token.NoPos {
position := c.fset.PositionFor(pos, false)
// All packages passed on the command line are being
// loaded from source. However, thanks to tests and
// test variants of packages, we encounter the same
// object many different times. Worse, some of these
// forms may have been loaded from export data
// (despite being a variant of a package we've loaded
// from source…). Objects from export data do not have
// column information, so we force it to one, so that
// objects loaded from source and from export have the
// same position.
//
// SImilarly, the "offset" differs, too.

position.Column = 1
position.Offset = 0
c.seenMu.Lock()
c.seen[position] = struct{}{}
c.seenMu.Unlock()
Expand Down

0 comments on commit 2f699b8

Please sign in to comment.