diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-11-09 09:54:21 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-11-09 09:54:21 +0300 |
| commit | c571f017a0d2c6ce750d97f00f493c48a1859ff3 (patch) | |
| tree | 6ddfe4a368d0c68b3df8e2a00a06b5efa6e9a833 /macros | |
| parent | ae76d82a06a9fcfe84ee0ae86f4a5440eaf0b656 (diff) | |
fix(macros): do not insert arity error closure for functions with >= 0 arity
Diffstat (limited to 'macros')
| -rw-r--r-- | macros/fn.fnl | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/macros/fn.fnl b/macros/fn.fnl index 8146a0b..cdd1257 100644 --- a/macros/fn.fnl +++ b/macros/fn.fnl @@ -72,14 +72,15 @@ (lua :break)))) res) -(fn grows-by-one? [tbl] +(fn grows-by-one-or-equal? [tbl] (let [t []] (each [_ v (ipairs tbl)] (insert t v)) (sort t) (var prev nil) (each [_ cur (ipairs t)] (if prev - (when (not= (+ prev 1) cur) + (when (and (not= (+ prev 1) cur) + (not= prev cur)) (lua "return false"))) (set prev cur)) prev)) @@ -117,10 +118,10 @@ (assert-compile (not (and max (<= more-len max))) "fn*: arity with `& more' must have more arguments than maximum arity without `& more'. * Try adding more arguments before `&'" arity) - (insert lengths more-len) + (insert lengths (- more-len 1)) (insert bodies (list '>= len (- more-len 1))) (insert bodies body))) - (if (not (and (grows-by-one? lengths) + (if (not (and (grows-by-one-or-equal? lengths) (contains? lengths 0))) (insert bodies (list 'error (.. "wrong argument amount" |