File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change 1499
1499
(core/defn- add-ifn-methods [type type-sym [f & meths :as form]]
1500
1500
(core/let [meths (map #(adapt-ifn-params type %) meths)
1501
1501
this-sym (with-meta 'self__ {:tag type})
1502
- argsym (gensym " args" )]
1502
+ argsym (gensym " args" )
1503
+ max-ifn-arity 20 ]
1503
1504
(concat
1504
1505
[`(set! ~(extend-prefix type-sym 'call) ~(with-meta `(fn ~@meths) (meta form)))
1505
1506
`(set! ~(extend-prefix type-sym 'apply)
1506
1507
~(with-meta
1507
1508
`(fn ~[this-sym argsym]
1508
1509
(this-as ~this-sym
1509
1510
(.apply (.-call ~this-sym) ~this-sym
1510
- (.concat (array ~this-sym) (cljs.core/aclone ~argsym)))))
1511
+ (.concat (array ~this-sym)
1512
+ (if (> (.-length ~argsym) ~max-ifn-arity)
1513
+ (doto (.slice ~argsym 0 ~max-ifn-arity)
1514
+ (.push (.slice ~argsym ~max-ifn-arity)))
1515
+ ~argsym)))))
1511
1516
(meta form)))]
1512
1517
(ifn-invoke-methods type type-sym form))))
1513
1518
Original file line number Diff line number Diff line change 42
42
(is (= '(1 2 3 4 )) (apply meta-f 1 2 3 4 []))
43
43
(is (= '(1 2 3 4 5 )) (apply meta-f 1 2 3 4 5 []))
44
44
(is (= (range 1 8 )) (apply meta-f 1 2 3 4 5 [6 7 ]))
45
- ; ; Currently: 20 is not seqable :(
46
- #_ (is (= (range 21 ) (apply meta-f (range 21 )))
45
+ (is (= (range 21 ) (apply meta-f (range 21 )))
47
46
" Should properly call the last IFn arity with 20 args with last being a seq" )
48
- ; ; Currently: Tries to call arity 21. Fault at .apply of the deftype proto
49
- ; ; Though, it could probably also be caught right by apply
50
- #_ (is (= (range 22 ) (apply meta-f (range 22 )))
47
+ (is (= (range 22 ) (apply meta-f (range 22 )))
51
48
" Should properly call the last IFn arity with 20 args with last being a seq" )
52
- # _ (is (= (range 22 ) (.apply meta-f nil (to-array (range 22 ))))
49
+ (is (= (range 22 ) (.apply meta-f nil (to-array (range 22 ))))
53
50
" .apply should also handle >20 arguments" ))
54
51
55
52
(deftest multi-arity-test
You can’t perform that action at this time.
0 commit comments