~xerool/fennel-ls#23: 
`(case ... [a a] ...)` should not trigger unused definition warning

(case [1 1]
  [a a] true ;; unused definition: a
  _ false)

a is implicitly used when checking that both elements are equal.

Status
RESOLVED FIXED
Submitter
~rktjmp
Assigned to
No-one
Submitted
1 year, 2 months ago
Updated
5 months ago
Labels
needs-design

~xerool referenced this from #22 1 year, 2 months ago

~xerool 1 year, 2 months ago

Actually, this one has a different root cause than fennel-ls#22.

Fennel-ls doesn't have the builtin macros built in; it actually depends on the macroexpansion, and then maps the lints back to the source AST if the corresponding AST elements are present in both. Unfortunately, in the macroexpansion, a is actually unused.

(let [(_1_) [1 1]] (if (and (= (_G.type _1_) "table") (not= nil (. _1_ 1)) (= (. _1_ 1) (. _1_ 2))) (let [a (. _1_ 1)] true) true (let [_ _1_] false)))

This means there's not much I can do to make this go away unless I start hardcoding special behaviors for specific macros.

~technomancy REPORTED FIXED 5 months ago

Implemented this in e5dc047 by ignoring unused locals ending in underscores same as #23.

~xerool 5 months ago

To be clear, the solution is to change your code like so:

(case [1 1]
  [a_ a_] true
  _ false)

A trailing _ suppresses the lint without changing the meaning of the pattern.

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