Skip to content

Commit fb312cd

Browse files
committed
CLJS-2733: Throw error message if too few or too many args to throw
same as CLJ-1456
1 parent 0cdbb23 commit fb312cd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/clojure/cljs/analyzer.cljc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,8 +1394,15 @@
13941394
:children (vec (concat [v] tests thens (if default [default])))}))
13951395

13961396
(defmethod parse 'throw
1397-
[op env [_ throw :as form] name _]
1398-
(let [throw-expr (disallowing-recur (analyze (assoc env :context :expr) throw))]
1397+
[op env [_ throw-form :as form] name _]
1398+
(cond
1399+
(= 1 (count form))
1400+
(throw
1401+
(error env "Too few arguments to throw, throw expects a single Error instance"))
1402+
(< 2 (count form))
1403+
(throw
1404+
(error env "Too many arguments to throw, throw expects a single Error instance")))
1405+
(let [throw-expr (disallowing-recur (analyze (assoc env :context :expr) throw-form))]
13991406
{:env env :op :throw :form form
14001407
:throw throw-expr
14011408
:children [throw-expr]}))

0 commit comments

Comments
 (0)