-
Notifications
You must be signed in to change notification settings - Fork 67
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
Clojure macro introduces name -- Joker thinks it is not declared #20
Comments
I am open to suggestions on how to improve the algorithm though. As a side note, I almost feel like Joker should flag things like this and discourage macros that implicitly introduce new bindings. They may be very confusing, especially for someone new to the codebase, and can generally be the source of subtle bugs. For example, what if the above snippet is wrapped in something like |
Yup, that's all totally reasonable. I realized that if the macro accepted the symbol name to introduce as the first element of the vector, the warning goes away:
It looks like the macro logic assumes that symbols in the first argument are introduced as global symbols? I put a test symbol in that vector and Joker no longer flagged undefined instances of that same symbol lower in the file. That's not a criticism (nor really a bug) -- I'm just trying to establish the rules that Joker uses. I'd actually be happy to update our macro so the I'll be opening a new issue soon with some Expectations code that Joker flags, that I'm not sure what to do about (summary: Expectations has a |
Your second example works because Joker first encounters
|
I would expect such macros to only introduce local names tho', not top-level names.
|
Good point. Not sure if distinguishing those two cases is worth additional complexity but I'll see what I can do.
So each element in |
Nice! So I'd be able to say |
@candid82 Looks like some nice changes since v0.8.3 -- is v0.8.4 on the horizon yet, or do you have other features/fixes planned before the next release? |
I'll see if I can squeeze in other fixes, but planning on releasing v0.8.4 this week. RE: distinguishing top level vs. local bindings inside macros. I played with the idea a bit but ultimately decided to abandon it (at least for now). Simple heuristic like "top level symbols inside a macro call introduce top level var, everything else creates a local binding" break down in macros like |
I look forward to testing the new release. Thank you! |
I have a macro that introduces a local symbol and it's used like this:
The macro takes
(:params req)
, applies the conformingclojure.spec
stuff, and introduces a local binding ofparams
. Unfortunately, Joker flags the use ofparams
on the next line as invalid.I verified that
:known-macros
is working correctly here: if I addfoo
immediately afterwith-validated-params
in that code, Joker doesn't flag that -- so it's assuming that a macro is invoked with a symbol and that is defining something new.I guess it doesn't allow for a deliberately unhygienic macro that introduces a new local binding?
The text was updated successfully, but these errors were encountered: