Skip to content

Commit

Permalink
CLJS-3382: Fix regression in .apply after CLJS-3024 (#182)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikita Prokopov <[email protected]>
  • Loading branch information
swannodette and tonsky authored Jun 21, 2022
1 parent e4ff22f commit 7af8c42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/main/clojure/cljs/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1507,12 +1507,13 @@
~(with-meta
`(fn ~[this-sym argsym]
(this-as ~this-sym
(.apply (.-call ~this-sym) ~this-sym
(.concat (array ~this-sym)
(if (> (.-length ~argsym) ~max-ifn-arity)
(doto (.slice ~argsym 0 ~max-ifn-arity)
(.push (.slice ~argsym ~max-ifn-arity)))
~argsym)))))
(let [args# (cljs.core/aclone ~argsym)]
(.apply (.-call ~this-sym) ~this-sym
(.concat (array ~this-sym)
(if (> (.-length args#) ~max-ifn-arity)
(doto (.slice args# 0 ~max-ifn-arity)
(.push (.slice args# ~max-ifn-arity)))
args#))))))
(meta form)))]
(ifn-invoke-methods type type-sym form))))

Expand Down
5 changes: 4 additions & 1 deletion src/test/cljs/cljs/apply_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
(is (= (range 22) (apply meta-f (range 22)))
"Should properly call the last IFn arity with 20 args with last being a seq")
(is (= (range 22) (.apply meta-f nil (to-array (range 22))))
".apply should also handle >20 arguments"))
".apply should also handle >20 arguments")
(let [ctor #(.apply meta-f nil (js-arguments))] ; CLJS-3382
(is (= '(1 2 3) (.apply ctor nil #js [1 2 3])))
(is (= (range 30) (.apply ctor nil (to-array (range 30)))))))

(deftest multi-arity-test
(is (= 2 (apply (fn ([a] a) ([a b] b)) 1 [2])))
Expand Down

0 comments on commit 7af8c42

Please sign in to comment.