Skip to content

Commit c2296b1

Browse files
committedApr 23, 2015
CLJS-1216: regression, varargs not passed properly
Calculation of max fixed arity did not consider the variadic signature
1 parent 341d41b commit c2296b1

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed
 

‎src/clj/cljs/core.clj

+9-3
Original file line numberDiff line numberDiff line change
@@ -2146,9 +2146,13 @@
21462146
(fn ~method))))]
21472147
(core/let [rname (symbol (core/str ana/*cljs-ns*) (core/str name))
21482148
arglists (map first fdecl)
2149-
variadic (boolean (some #(some '#{&} %) arglists))
2150-
sigs (remove #(some '#{&} %) arglists)
2151-
maxfa (apply core/max (map count sigs))
2149+
varsig? #(some '#{&} %)
2150+
variadic (boolean (some varsig? arglists))
2151+
sigs (remove varsig? arglists)
2152+
maxfa (apply core/max
2153+
(concat
2154+
(map count sigs)
2155+
[(core/- (count (first (filter varsig? arglists))) 2)]))
21522156
meta (assoc meta
21532157
:top-fn
21542158
{:variadic variadic
@@ -2181,6 +2185,8 @@
21812185
(pp/pprint (multi-arity-fn 'foo {} '(([a]) ([a b]))))
21822186
(pp/pprint (multi-arity-fn 'foo {} '(([a]) ([a & xs]))))
21832187
(pp/pprint (multi-arity-fn 'foo {} '(([a]) ([a [b & cs] & xs]))))
2188+
;; CLJS-1216
2189+
(pp/pprint (multi-arity-fn 'foo {} '(([a]) ([a b & xs]))))
21842190
)
21852191

21862192
(def

‎test/cljs/cljs/core_test.cljs

+20
Original file line numberDiff line numberDiff line change
@@ -2751,6 +2751,26 @@
27512751
(testing "array-map should skip dropped elements of IndexedSeq"
27522752
(is (= {:a 1} (apply array-map (drop 1 [0 :a 1]))))))
27532753

2754+
(defn foo-1216
2755+
([a] (foo-1216 a 10))
2756+
([a b & [c]] [a b c]))
2757+
2758+
(defn destructure-1216
2759+
([kvs] kvs)
2760+
([k v & args] [k v args]))
2761+
2762+
(deftest test-cljs-1216
2763+
(testing "varargs regression"
2764+
(is (= (foo-1216 1) [1 10 nil]))
2765+
(is (= (foo-1216 1 2) [1 2 nil]))
2766+
(is (= (foo-1216 1 2 3) [1 2 3]))
2767+
(is (= [1 2 [3 4]]
2768+
(destructure-1216 1 2 3 4)))
2769+
(is (= [1 2 [3 4]]
2770+
(apply destructure-1216 [1 2 3 4])))
2771+
(is (= (destructure-1216 1 2 3 4)[1 2 [3 4]]
2772+
(apply destructure-1216 [1 2 3 4])))))
2773+
27542774
(comment
27552775
;; ObjMap
27562776
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)
Please sign in to comment.