diff --git a/src/fennel-ls/compiler.fnl b/src/fennel-ls/compiler.fnl index 1525c3f..aa2c71e 100644 --- a/src/fennel-ls/compiler.fnl +++ b/src/fennel-ls/compiler.fnl @@ -184,7 +184,8 @@ later by fennel-ls.language to answer requests from the client." (where [_fn _name args] (fennel.sequence? args)) args _ [])) (each [_ argument (ipairs args)] - (define (sym :nil) argument scope))) ;; TODO for now, function arguments are set to nil + (if (not (sym? argument :&)) + (define (sym :nil) argument scope)))) ;; TODO for now, function arguments are set to nil (λ define-function [ast scope] ;; handle the definitions of a function diff --git a/test/diagnostic-test.fnl b/test/diagnostic-test.fnl index 6c39a50..48de5c3 100644 --- a/test/diagnostic-test.fnl +++ b/test/diagnostic-test.fnl @@ -25,7 +25,7 @@ diagnostic (match responses [{:params {: diagnostics}}] - (is (find [i v (ipairs diagnostics)] + (is (find [_ v (ipairs diagnostics)] (match v {:message "tried to reference a special form without calling it" :range {:start {:character 4 :line 0} @@ -41,7 +41,7 @@ diagnostic (match responses [{:params {: diagnostics}}] - (is (find [i v (ipairs diagnostics)] + (is (find [_ v (ipairs diagnostics)] (match v {:message "expected whitespace before opening delimiter (" :range {:start {:character 17 :line 0} @@ -72,7 +72,7 @@ responses (self:open-file! filename "(local x 10)")] (match responses [{:params {: diagnostics}}] - (is (find [i v (ipairs diagnostics)] + (is (find [_ v (ipairs diagnostics)] (match v {:message "unused definition: x" :range {:start {:character 7 :line 0} @@ -86,7 +86,7 @@ responses (self:open-file! filename "(fn x [])")] (match responses [{:params {: diagnostics}}] - (is (find [i v (ipairs diagnostics)] + (is (find [_ v (ipairs diagnostics)] (match v {:message "unused definition: x" :range {:start {:character 4 :line 0} @@ -105,7 +105,7 @@ responses (self:open-file! filename "(var x 1) (set x 2) (set [x] [3])")] (match responses [{:params {: diagnostics}}] - (is (find [i v (ipairs diagnostics)] + (is (find [_ v (ipairs diagnostics)] (match v {:message "unused definition: x" :range {:start {:character 5 :line 0} @@ -114,17 +114,27 @@ "not found") _ (error "did not match")))) - (it "does not warn in this particular code" + (it "does not warn on ampersand in destructuring" (let [self (create-client) responses (self:open-file! filename "(let [[x & y] [1 2 3]] (print x (. y 1) (. y 2)))")] (match responses [{:params {: diagnostics}}] - (is.nil (find [i v (ipairs diagnostics)] + (is.nil (find [_ v (ipairs diagnostics)] (match v {:message "unused definition: &"} v)) "not found") - _ (error "did not match"))))) + _ (error "did not match")))) + + (it "does not warn on ampersand in function parameters" + (let [self (create-client) + responses (self:open-file! filename "(fn [x & more] (print x more))")] + (match responses + [{:params {: diagnostics}}] + (is.nil (find [_ v (ipairs diagnostics)] + (match v + {:message "unused definition: &"} + v)))))))