Skip to content

Commit be51827

Browse files
anmonteiroswannodette
authored andcommitted
CLJS-2005: Bad error message with duplicate arity function definitions
1 parent e35dd45 commit be51827

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/clojure/cljs/core.cljc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2973,7 +2973,10 @@
29732973
:method-params sigs
29742974
:arglists arglists
29752975
:arglists-meta (doall (map meta arglists))})
2976-
args-sym (gensym "args")]
2976+
args-sym (gensym "args")
2977+
param-counts (map count arglists)]
2978+
(core/when (not= (distinct param-counts) param-counts)
2979+
(ana/warning :overload-arity {} {:name name}))
29772980
`(do
29782981
(def ~(with-meta name meta)
29792982
(fn [~'var_args]

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,17 @@
482482
(println x)))))
483483
(is (.startsWith (first @ws) "js/foo is shadowed by a local"))))
484484

485+
(deftest test-cljs-2005
486+
(let [ws (atom [])]
487+
(try
488+
(a/with-warning-handlers [(collecting-warning-handler ws)]
489+
(a/analyze (a/empty-env)
490+
'(defn myfun
491+
([x] x)
492+
([x] x))))
493+
(catch Exception _))
494+
(is (.startsWith (first @ws) "myfun: Can't have 2 overloads with same arity"))))
495+
485496
(deftest test-canonicalize-specs
486497
(is (= (a/canonicalize-specs '((quote [clojure.set :as set])))
487498
'([clojure.set :as set])))

0 commit comments

Comments
 (0)