;; given the same binding name, the second `n` is marked as unused.
(case [:a 1]
(where (or [:a n] [:b n])) n
_ false)
;; ./fennel-ls --check bug/case-undef.fnl
;; bug/case-undef.fnl:2:24 unused definition: n
I'm having trouble figuring out why this is happening. I'm testing with
(case 1 (where (or x x)) x)This expands to
(let [(_1_) 1] (if true (let [(matched?_2_ x_3_) (if (not= nil _1_) (let [x _1_] (values true x)) (not= nil _1_) (let [x _1_] (values true x)))] (if matched?_2_ (let [(x) (values x_3_)] x)))))There are 3 "definitions" of "x" here, and every single one of them is referenced once, so something is not going right.
I really need to come up with better ways to visualize the internal state of fennel-ls, because what I'm doing right now is miserable. Scope objects take up a million lines; symbols are distinct but indistinguishible because they're all called "x"; there's no way to see which symbols are which in the expanded ast because they only have bytestart/byteend file metadata for their literal position in the file.
I figured out what's causing this and fennel-ls#23. Right now, I make the assumption that any particular instance of an identifier in the ast can only reference one thing. However, in this case (no pun intended) the first
x
symbol is used to referencex
, and then the same instance is used in the macroexpansion to reference the otherx
. Fennel-ls currently misses the second reference but we should count it.
Okay, I fixed this one! I'm not sure what to do about the other ones though.