diff --git a/unused/unused.go b/unused/unused.go index 279621614..98cba11e7 100644 --- a/unused/unused.go +++ b/unused/unused.go @@ -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) } @@ -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()