Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong unresolved error on defmacro #2291

Open
1 task done
licht1stein opened this issue Feb 23, 2024 · 1 comment
Open
1 task done

Wrong unresolved error on defmacro #2291

licht1stein opened this issue Feb 23, 2024 · 1 comment

Comments

@licht1stein
Copy link

[ To keep development of this project going, consider sponsoring. If you are
already a sponsor, thank you! ]

  • I have read the Clojure etiquette and will respect it when communicating on this platform.

version
clj-kondo v2024.02.12

macro usage
The bug is related to a macro, but it was linting fine before. Macro config:

{:lint-as {b.jobs.helpers/defjob clojure.core/defn}}

platform
Native, installed via homebrew

editor
Emacs

problem
After defining a macro, it's invocation is not recognised:

./components/jobs/src/b/jobs/core.clj:8:34: warning: Unresolved var: defjob
./components/jobs/src/b/jobs/helpers.clj:51:4: error: Unresolved symbol: defjob
./components/jobs/src/b/jobs/helpers.clj:51:11: error: Unresolved symbol: foo

repro

(ns b.jobs.helpers)

(def job-registry (atom #{}))

(defn register-job
  [{:keys [:job/id] :as job}]
  (when (empty? (filter #(= id (:job/id %)) @job-registry))
    (swap! job-registry conj job)))

(defn response
  [{:keys [id ok? message result]}]
  (let [resp (cond->
              {:id id
               :ok? (if (false? ok?) ok? true)}
               (some? message) (assoc :message message)
               (some? result) (assoc :result result))]
    resp))

(defmacro defjob
  "Like defn, but turns a function into a job. Docstring required."
  [name docstring args body]
  (let [job-id (keyword name)]
    `(do
       (def ~name
         ~docstring
         (fn ~args
           (try
             (response {:result ~body
                        :id ~job-id})
             (catch Exception e#
               (response {:ok? false
                          :id ~job-id
                          :result (str e#)})))))

       (register-job {:job/id ~job-id
                      :job/description ~docstring
                      :job/callback ~name})
       ~name)))

;; This usage is marked as error
(defjob foo "bar" [] 1)

config
I didn't modify config since upgrading clj-kondo.

expected behavior
Do not mark defjob usage as error.

@borkdude
Copy link
Member

borkdude commented Feb 23, 2024

I can't reproduce this.

borkdude@m1 ~/dev/scratch $ clj-kondo --lint src/repro.clj
linting took 52ms, errors: 0, warnings: 0
borkdude@m1 ~/dev/scratch $ cat .clj-kondo/config.edn
{:lint-as {
           repro/defjob clojure.core/defn}}

Can you perhaps make a separate Github repository for repro and show a stepwise reproduction?
Perhaps there is something stateful going on in your project. Perhaps you have multiple files with the same namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants