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

unresolved symbol error with syntax quotes #648

Closed
alidcast opened this issue Dec 12, 2019 · 7 comments
Closed

unresolved symbol error with syntax quotes #648

alidcast opened this issue Dec 12, 2019 · 7 comments

Comments

@alidcast
Copy link

clj-kondo v2019.10.26
vscode

problem

following discussion on slack, in snippet below ~@args# gives an unresolved symbol error but as you responded it is valid syntax

(defn example
  [name]
  `(defmacro ~name [& args#]
     `(foo ~(keyword '~name) ~@args#)))

expected behavior

allow nesting of syntax quotes

@borkdude borkdude added this to Needs triage in clj-kondo via automation Dec 12, 2019
@borkdude borkdude moved this from Needs triage to High priority (next release) in clj-kondo Dec 12, 2019
@alidcast
Copy link
Author

alidcast commented Dec 13, 2019

another macro related issue is requiring a namespace used inside a nested macro but getting a required but never used warning

below lib.foo is highlighted for not being used
ex.

(ns example (require [lib.foo :as foo])
(defn nested-macro [tag]
  `(defmacro ~(symbol tag) [& args#]
     `(foo ~@args#)))

but there is no warning if macro is not nested under a function (so snippet below would resolve the above warning), hence why i think it is also an uncovered edge case

(defmacro only-me [& args#]
  `(foo ~@args#)))

@alidcast alidcast changed the title unresolved symbol error with nested syntax quotes unresolved symbol error with syntax quotes Dec 13, 2019
@borkdude borkdude moved this from High priority (next release) to In progress in clj-kondo Dec 14, 2019
@borkdude
Copy link
Member

@alidcastano

  1. You have a typo in this example, require should be :require.
  2. A namespace alias cannot be called as a function (unless in CLJS maybe), that's why the namespace is not used.

@alidcast
Copy link
Author

ah my fault, i tried to trim down the example and accidently made it incorrect. the actual example was doing ns/fn, as you stated.

for exact code, here's the library I cloned locally where I was seeing the above warning:

the require call [1]:
(:require [helix.core :as hx])

the macro that is using it [2]:

#?(:clj (defn gen-tag
          [tag]
          `(defmacro ~tag [& args#]
             `(hx/$ ~(keyword '~tag) ~@args#))))

so in above example helix.core has the following warning in vscode: namespace helix.core is required but never use

[1] https://github.com/Lokeh/helix/blob/60d0fe746f4bce0d341fdac947039d489d672a16/src/helix/dom.cljc#L3

[2] https://github.com/Lokeh/helix/blob/60d0fe746f4bce0d341fdac947039d489d672a16/src/helix/dom.cljc#L139-L142

@borkdude
Copy link
Member

@alidcastano In this case the warning appears because the library is only used in CLJ but not in CLJS.

@borkdude borkdude moved this from In progress to Next release in clj-kondo Dec 14, 2019
@borkdude
Copy link
Member

Fixed with ff48c9a

@alidcast
Copy link
Author

thanks for clarifying above misunderstanding and fixing this issue, will go ahead and close this

clj-kondo automation moved this from Next release to Done Dec 14, 2019
@borkdude borkdude reopened this Dec 14, 2019
clj-kondo automation moved this from Done to Needs triage Dec 14, 2019
@borkdude
Copy link
Member

@alidcastano Thank you for reporting! I'll close the issue after releasing a new version. I keep the issues open as a reminder to write something about it in the release notes.

@borkdude borkdude moved this from Needs triage to Next release in clj-kondo Dec 14, 2019
clj-kondo automation moved this from Next release to Done Dec 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
clj-kondo
  
Done
Development

No branches or pull requests

2 participants