unused: don't be over-eager in deduplicating objects
Multiple objects may be defined on the same line, and since we're
discarding column information, their positions are no longer unique.
Incorporate the object's string representation to account for this.
@@ -403,6 +403,11 @@ type pkg struct {
SrcFuncs []*ssa.Function
}
+type seenKey struct {
+ s string
+ pos token.Position
+}
+
type Checker struct {
mu sync.Mutex
@@ -413,7 +418,7 @@ type Checker struct {
allPackages map[*types.Package]struct{}
seenMu sync.Mutex
- seen map[token.Position]struct{}
+ seen map[seenKey]struct{}
graph *Graph
out []types.Object
@@ -422,7 +427,7 @@ type Checker struct {
func NewChecker() *Checker {
c := &Checker{
- seen: map[token.Position]struct{}{},
+ seen: map[seenKey]struct{}{},
initialPackages: map[*types.Package]struct{}{},
allPackages: map[*types.Package]struct{}{},
}
@@ -531,7 +536,8 @@ func (c *Checker) Result() []types.Object {
position := c.fset.PositionFor(v.Pos(), false)
position.Column = 1
position.Offset = 0
- if _, ok := c.seen[position]; !ok {
+ k := seenKey{v.String(), position}
+ if _, ok := c.seen[k]; !ok {
out2 = append(out2, v)
}
}
@@ -673,7 +679,6 @@ func (c *Checker) results() []types.Object {
var pos token.Pos
if obj, ok := node.obj.(types.Object); ok {
pos = obj.Pos()
- }
if pos != token.NoPos {
position := c.fset.PositionFor(pos, false)
@@ -688,14 +693,16 @@ func (c *Checker) results() []types.Object {
// objects loaded from source and from export have the
// same position.
//
- // SImilarly, the "offset" differs, too.
+ // Similarly, the "offset" differs, too.
position.Column = 1
position.Offset = 0
+ k := seenKey{obj.String(), position}
c.seenMu.Lock()
- c.seen[position] = struct{}{}
+ c.seen[k] = struct{}{}
c.seenMu.Unlock()
}
+ }
return
}
if node.quiet {
