Right, actually I think a better heuristic would be: "warn on any function
invocation where the function being invoked is a local binding with a name
shadowing clojure.core". Whenever I use these names in local bindings,
they're practically never functions so invoking them is pretty much always
a bug. I think shadowing a core function with another function is
sufficiently unusual that it deserves a warning. The false positives from
this would be minimal and it requires no type information.

However when I think about it, this is not generally the problem I have
with these cases. The problem is almost always that I've copied some code
from inside a block defining such a local variable and then pasted it
somewhere else. Then Cursive doesn't warn me about the unresolved local
variable since the variable now resolves to the core function and I get an
error like:

(+ count 10)
ClassCastException clojure.core$count cannot be cast to java.lang.Number
clojure.lang.Numbers.add (Numbers.java:126)

This case is much harder to catch but is definitely the case that happens
to me much more frequently. It might be possible to warn in some cases with
a "suspicious higher-order use of core function" or similar when passing a
core function in a place that doesn't appear to accept a HOF, but again you
need a certain degree of type information there and you can't really warn
if the user is storing the variable in a map or similar.


On 30 July 2014 23:29, Sean Corfield <s...@corfield.org> wrote:

> On Jul 30, 2014, at 1:37 PM, Andy Fingerhut <andy.finger...@gmail.com>
> wrote:
> > My first thought at a lint implementation was simply "warn if a
> let-bound name matches any Var name in clojure.core", although granted that
> could produce more false positives than you want.
>
> Yeah, I'd just disable that globally for our code base.
>
> I think Colin's suggestion is solid, if you can do it. I don't think we
> shadow a core function with a local function anywhere and such attempted
> calls would almost certainly be bugs - or at least indicate a better
> function name was needed.
>
> Sean Corfield -- (904) 302-SEAN
> An Architect's View -- http://corfield.org/
>
> "Perfection is the enemy of the good."
> -- Gustave Flaubert, French realist novelist (1821-1880)
>
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to