Skip to content

Commit e4e4a29

Browse files
mfikesdnolen
authored andcommitted
CLJS-2741: Function invoke errors report arity off by 1
1 parent a3039bd commit e4e4a29

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/clojure/cljs/compiler.cljc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,10 @@
906906
(emitln "return " n ".call(this" (if (zero? pcnt) nil
907907
(list "," (comma-sep (take pcnt maxparams)))) ");"))))
908908
(emitln "}")
909-
(emitln "throw(new Error('Invalid arity: ' + (arguments.length - 1)));")
909+
(let [arg-count-js (if (= 'self__ (-> ms first val :params first :name))
910+
"(arguments.length - 1)"
911+
"arguments.length")]
912+
(emitln "throw(new Error('Invalid arity: ' + " arg-count-js "));"))
910913
(emitln "};")
911914
(when variadic
912915
(emitln mname ".cljs$lang$maxFixedArity = " max-fixed-arity ";")

src/test/cljs/cljs/core_test.cljs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,17 @@
15371537
;; Make sure we didn't delete the alpha? fn
15381538
(is (some? alpha-2585?)))
15391539

1540+
(defn fn-2741* ([x]) ([x y]))
1541+
(def fn-2741 fn-2741*)
1542+
1543+
(deftest test-cljs-2741
1544+
(is (thrown-with-msg? js/Error #".*Invalid arity: 0" ((fn ([x]) ([x y])))))
1545+
(is (thrown-with-msg? js/Error #".*Invalid arity: 3" ((fn ([x]) ([x y])) 1 2 3)))
1546+
(is (thrown-with-msg? js/Error #".*Invalid arity: 0" (fn-2741)))
1547+
(is (thrown-with-msg? js/Error #".*Invalid arity: 3" (fn-2741 1 2 3)))
1548+
(is (thrown-with-msg? js/Error #".*Invalid arity: 0" ({})))
1549+
(is (thrown-with-msg? js/Error #".*Invalid arity: 3" ({} 1 2 3))))
1550+
15401551
(comment
15411552
;; ObjMap
15421553
;; (let [ks (map (partial str "foo") (range 500))

0 commit comments

Comments
 (0)