cursive 2025-12-17

can someone check if cursive complains about this:

(ns foo (:refer-clojure :exclude [def]))

(defn def [])
when you remove :exclude [def]? Basically :exclude [def] is a no-op since def is a special form and can't be overridden in call sites

I'm not seeing any error reported at defn def with or without the exclusion

good to know

to be clear: it shouldn't warn, so the status quo is good

I might be missing something. If def can't be overwritten, then I'd consider the code above worthy of a warning

As in "hey, this code doesn't do what you might expect it to do"

that's what I'm going to do in clj-kondo now, but without the exclude it shouldn't warn that def is overwritten

without the exclude it shouldn't warn - but you won't ever be able to call the def function no? - without an explicit namespace prefix, I suppose

true. one example of this is clojure.spec.alpha/def

defining a function/macro called def IMO isn't great practice and I'd surely flag that in a code review

ok, make a JIRA I guess? ;)

I suppose this could apply to all names "shadowing" any special form

that's a somewhat different but related issue

description says "We should also warn on using special form names as var names"

also, it already works so it seems I can close the issue.

yeah we could warn on that

let me record a new one specific to this conversation and link to this

what are you going to record?

I'm asking to prevent creating a duplicate one ;)

I'll just add a comment then, saying that it would be lovely to have a warning every time a special form is "attempted to be shadowed" - not just var names, locals too

ok, I think I'll close this issue so you can make a new one

not sure if I have a test for this

let me check

I found this one:

(deftest special-form-test
  (is (empty?
       (lint! "(defn new [] :foo)
               (new js/Date 2022 1 1 1 1)"
              "--lang" "cljs"))))

ok, I added another test for 639

and closed it

(apologies for hijacking the thread)

We do have :shadowed-var btw, but I never use it myself. It already warns for special forms it seems:

$ clj -M:clj-kondo/dev --config '{:linters {:shadowed-var {:level :warning}}}' --lint - <<< "(let [var 1] var)"
<stdin>:1:7: warning: Shadowed var: clojure.core/var
linting took 32ms, errors: 0, warnings: 1

In the linted example here, you don't call the special form

good to know there's support

maybe good to mention it in the issue

👍 1

although I'd say special forms are a bit more special in this case

because shadowing them will not really work

shadowing will work, as long as you don't call them, but just reference them as values

that's the not >really< part I guess 🙂

anyway, I don't want to waste your time 🙂

the failure modes are somewhat different between shadowing special forms and vars

added this to the issue, feel free to close if considered covered by shadowed-var