Welcome! Please see the About page for a little more info on how this works.

+1 vote
in ClojureScript by

Defining a multimethod with varargs, then using apply on a seqable with more than 20 items fails.

The error is different depending on whether there's exactly 21 args or more.

This behavior is not observed in normal function definitions.

ClojureScript 1.10.439
cljs.user=> (defmulti foo (fn (link: & args) (first args)))

'cljs.user/foo

cljs.user=> (defmethod foo 0 (link: & args))

object(link: cljs.core.MultiFn)

cljs.user=> (apply foo (range 20))
nil

cljs.user=> (apply foo (range 21))
Error: 20 is not ISeqable

 cljs$core$seq (.cljs_nashorn_repl/cljs/core.cljs:1223:13)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3739:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$spread (.cljs_nashorn_repl/cljs/core.cljs:3740:9)
 cljs$core$IFn$_invoke$arity$variadic (.cljs_nashorn_repl/cljs/core.cljs:3926:6)
 G__12749__22 (.cljs_nashorn_repl/cljs/core.cljs:10998:5)
 G__12749 (.cljs_nashorn_repl/cljs/core.cljs:10868:1)
 apply (.cljs_nashorn_repl/cljs/core.cljs:10868:1)
 cljs$core$IFn$_invoke$arity$6 (.cljs_nashorn_repl/cljs/core.cljs:3885:6)
 cljs$core$IFn$_invoke$arity$5 (.cljs_nashorn_repl/cljs/core.cljs:3879:6)
 cljs$core$IFn$_invoke$arity$4 (.cljs_nashorn_repl/cljs/core.cljs:3873:6)
 cljs$core$IFn$_invoke$arity$3 (.cljs_nashorn_repl/cljs/core.cljs:3867:6)
 cljs$core$IFn$_invoke$arity$2 (.cljs_nashorn_repl/cljs/core.cljs:3861:6)
 cljs$core$IFn$_invoke$arity$2 (.cljs_nashorn_repl/cljs/core.cljs:3896:6)
 cljs$core$apply (.cljs_nashorn_repl/cljs/core.cljs:3887:1)
 (<NO_SOURCE_FILE> <eval>:1:0)
 (<NO_SOURCE_FILE> <eval>:1:0)
 (<NO_SOURCE_FILE> <eval>:1:0)

cljs.user=> (apply foo (range 22))
Error: Invalid arity: 22

 G__12749 (.cljs_nashorn_repl/cljs/core.cljs:36125:0)
 apply (.cljs_nashorn_repl/cljs/core.cljs:10868:1)
 cljs$core$IFn$_invoke$arity$6 (.cljs_nashorn_repl/cljs/core.cljs:3885:6)
 cljs$core$IFn$_invoke$arity$5 (.cljs_nashorn_repl/cljs/core.cljs:3879:6)
 cljs$core$IFn$_invoke$arity$4 (.cljs_nashorn_repl/cljs/core.cljs:3873:6)
 cljs$core$IFn$_invoke$arity$3 (.cljs_nashorn_repl/cljs/core.cljs:3867:6)
 cljs$core$IFn$_invoke$arity$2 (.cljs_nashorn_repl/cljs/core.cljs:3861:6)
 cljs$core$IFn$_invoke$arity$2 (.cljs_nashorn_repl/cljs/core.cljs:3896:6)
 cljs$core$apply (.cljs_nashorn_repl/cljs/core.cljs:3887:1)
 (<NO_SOURCE_FILE> <eval>:1:0)
 (<NO_SOURCE_FILE> <eval>:1:0)
 (<NO_SOURCE_FILE> <eval>:1:0)

cljs.user=> (defn bar (link: & args))

'cljs.user/bar

cljs.user=> (apply bar (range 100))
nil

2 Answers

0 votes
by

Comment made by: kanaka

I believe this is the same issue or closely related to https://clojure.atlassian.net/browse/CLJS-2446

I have encountered what I think is the same problem in a real-world situation (self-hosted mal/make-a-lisp using ClojureScript). It appears that metadata adorned functions have the same limit as multi-methods.

The following demonstrates using lumo but the same issues exist with AOT cljs running in a browser (Chrome):

`
Lumo 1.10.1
ClojureScript 1.10.520
Node.js v11.13.0
...
cljs.user=> (apply + (range 20))
190
cljs.user=> (apply + (range 21))
210
cljs.user=> (apply + (range 22))
231

cljs.user=> (apply (with-meta + {}) (range 20))
190
cljs.user=> (apply (with-meta + {}) (range 21))
20 is not ISeqable

 Object.cljs.core.seq (NO_SOURCE_FILE <embedded>:503:388)
 Object.cljs.core.spread (NO_SOURCE_FILE <embedded>:834:335)
 Object.cljs.core.spread (NO_SOURCE_FILE <embedded>:834:500)
 Object.cljs.core.spread (NO_SOURCE_FILE <embedded>:834:500)
 Object.cljs.core.spread (NO_SOURCE_FILE <embedded>:834:500)
 Object.cljs.core.spread (NO_SOURCE_FILE <embedded>:834:500)
 Object.cljs.core.spread (NO_SOURCE_FILE <embedded>:834:500)
 Object.cljs.core.spread (NO_SOURCE_FILE <embedded>:834:500)
 Object.cljs.core.spread (NO_SOURCE_FILE <embedded>:834:500)
 Object.cljs.core.spread (NO_SOURCE_FILE <embedded>:834:500)

cljs.user=> (apply (with-meta + {}) (range 22))
Invalid arity: 22

 (cljs.core.MetaFn.a)
 cljs.core.MetaFn.apply (NO_SOURCE_FILE <embedded>:603:289)
 Function.cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$6 (NO_SOURCE_FILE <embedded>:874:323)
 Function.cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$5 (NO_SOURCE_FILE <embedded>:867:205)
 Function.cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$4 (NO_SOURCE_FILE <embedded>:866:199)
 Function.cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:865:193)
 Function.cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$2 (NO_SOURCE_FILE <embedded>:864:188)
 Function.cljs.core.apply.cljs$core$IFn$_invoke$arity$2 (NO_SOURCE_FILE <embedded>:877:244)
 cljs.core.apply (NO_SOURCE_FILE <embedded>:875:84)
 (evalmachine.<anonymous>:1:17)

`

by
I came here to report this and I'm glad I found this issue. I'm seeing the same thing on anything with metadata, and in fact anything that implements `IFn`:

```
(let [args (repeat 21 0)]
  (apply (with-meta + {}) args))
```
0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-3024 (reported by alex+import)
...