Skip to content

Commit

Permalink
CLJS-1216: regression, varargs not passed properly
Browse files Browse the repository at this point in the history
Calculation of max fixed arity did not consider the variadic signature
  • Loading branch information
swannodette committed Apr 23, 2015
1 parent 341d41b commit c2296b1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/clj/cljs/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2146,9 +2146,13 @@
(fn ~method))))]
(core/let [rname (symbol (core/str ana/*cljs-ns*) (core/str name))
arglists (map first fdecl)
variadic (boolean (some #(some '#{&} %) arglists))
sigs (remove #(some '#{&} %) arglists)
maxfa (apply core/max (map count sigs))
varsig? #(some '#{&} %)
variadic (boolean (some varsig? arglists))
sigs (remove varsig? arglists)
maxfa (apply core/max
(concat
(map count sigs)
[(core/- (count (first (filter varsig? arglists))) 2)]))
meta (assoc meta
:top-fn
{:variadic variadic
Expand Down Expand Up @@ -2181,6 +2185,8 @@
(pp/pprint (multi-arity-fn 'foo {} '(([a]) ([a b]))))
(pp/pprint (multi-arity-fn 'foo {} '(([a]) ([a & xs]))))
(pp/pprint (multi-arity-fn 'foo {} '(([a]) ([a [b & cs] & xs]))))
;; CLJS-1216
(pp/pprint (multi-arity-fn 'foo {} '(([a]) ([a b & xs]))))
)

(def
Expand Down
20 changes: 20 additions & 0 deletions test/cljs/cljs/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,26 @@
(testing "array-map should skip dropped elements of IndexedSeq"
(is (= {:a 1} (apply array-map (drop 1 [0 :a 1]))))))

(defn foo-1216
([a] (foo-1216 a 10))
([a b & [c]] [a b c]))

(defn destructure-1216
([kvs] kvs)
([k v & args] [k v args]))

(deftest test-cljs-1216
(testing "varargs regression"
(is (= (foo-1216 1) [1 10 nil]))
(is (= (foo-1216 1 2) [1 2 nil]))
(is (= (foo-1216 1 2 3) [1 2 3]))
(is (= [1 2 [3 4]]
(destructure-1216 1 2 3 4)))
(is (= [1 2 [3 4]]
(apply destructure-1216 [1 2 3 4])))
(is (= (destructure-1216 1 2 3 4)[1 2 [3 4]]
(apply destructure-1216 [1 2 3 4])))))

(comment
;; ObjMap
;; (let [ks (map (partial str "foo") (range 500))
Expand Down

0 comments on commit c2296b1

Please sign in to comment.