Skip to content

Commit

Permalink
unused: named types use their pointer types
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikh committed May 12, 2019
1 parent ecb5372 commit 4187a5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions unused/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
edgeType
edgeTypeName
edgeUnderlyingType
edgePointerType
edgeUnsafeConversion
edgeUsedConstant
edgeVarDecl
Expand Down
16 changes: 9 additions & 7 deletions unused/edge_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions unused/unused.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import (
- (2.3) all their aliases. we can't easily track uses of aliases
because go/types turns them into uses of the aliased types. assume
that if a type is used, so are all of its aliases.
- (2.4) the pointer type. this aids with eagerly implementing
interfaces. if a method that implements an interface is defined on
a pointer receiver, and the pointer type is never used, but the
named type is, then we still want to mark the method as used.
- variables and constants use:
- their types
Expand Down Expand Up @@ -1420,6 +1424,9 @@ func (g *Graph) typ(t types.Type) {
g.seeAndUse(t.Obj(), t, edgeTypeName)
g.seeAndUse(t, t.Obj(), edgeNamedType)

// (2.4) named types use the pointer type
g.seeAndUse(types.NewPointer(t), t, edgePointerType)

for i := 0; i < t.NumMethods(); i++ {
g.see(t.Method(i))
// don't use trackExportedIdentifier here, we care about
Expand Down

0 comments on commit 4187a5f

Please sign in to comment.