venantius / yagni

A Leiningen plugin for finding dead code
Eclipse Public License 1.0
219 stars 10 forks source link

vars used only in protocol implementations are recognized as children #22

Closed NoamB closed 9 years ago

NoamB commented 9 years ago
(defprotocol FooBar
  (foo [this])
  (bar [this]))

(deftype MyCoolType []
  FooBar
  (foo [this]
    (my-func))
  (bar [this]
    (my-func))

functions foo and bar have parents, but my-func will still appear in children list.

venantius commented 9 years ago

I'd like to understand this issue a little better. What do you think the correct behavior here should be?

NoamB commented 9 years ago

If foo is used somewhere, then it is not a parent, hence my-func should not be a child.

venantius commented 9 years ago

Ah, I see. So really we'd want an additional line in your example, something like:

(foo (MyCoolType.))

Yeah?

venantius commented 9 years ago

After thinking about this some more I don't actually think this a bug.

If I include something like the following and set bar as an entrypoint then foo doesn't show up as either a parent or child, nor does my-func.

(defn bar []
  (foo (MyCoolType.)))

This is the intended behavior.

Similarly, if foo isn't called anywhere (or rather, isn't callable by some code path from an entrypoint), then we would expect both foo and my-func to be children.