~xerool/fennel-ls#22: 
Unused definition warning for dupicate bindings inside `case or`

;; 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
Status
RESOLVED FIXED
Submitter
~rktjmp
Assigned to
No-one
Submitted
1 year, 1 month ago
Updated
1 year, 1 month ago
Labels
No labels applied.

~xerool 1 year, 1 month ago*

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.

~xerool 1 year, 1 month ago

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 reference x, and then the same instance is used in the macroexpansion to reference the other x. Fennel-ls currently misses the second reference but we should count it.

~xerool referenced this from #23 1 year, 1 month ago

~xerool REPORTED FIXED 1 year, 1 month ago

Okay, I fixed this one! I'm not sure what to do about the other ones though.

Register here or Log in to comment, or comment via email.