Skip to content

Commit

Permalink
CLJ-2564 Improve error message for case
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Halloway <stu@cognitect.com>
  • Loading branch information
puredanger authored and stuarthalloway committed Sep 25, 2020
1 parent 3b6256e commit f25f3e2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/clj/clojure/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6696,6 +6696,9 @@ fails, attempts to require sym's namespace and retries."
(into1 #{} (map #(shift-mask shift mask %) skip-check)))]
[shift mask case-map switch-type skip-check]))))

(defn case-fallthrough-err-impl
[val]
(IllegalArgumentException. (str "No matching clause: " (pr-str val))))

(defmacro case
"Takes an expression, and a set of clauses.
Expand Down Expand Up @@ -6726,7 +6729,7 @@ fails, attempts to require sym's namespace and retries."
(let [ge (with-meta (gensym) {:tag Object})
default (if (odd? (count clauses))
(last clauses)
`(throw (IllegalArgumentException. (str "No matching clause: " ~ge))))]
`(throw (case-fallthrough-err-impl ~ge)))]
(if (> 2 (count clauses))
`(let [~ge ~e] ~default)
(let [pairs (partition 2 clauses)
Expand Down

0 comments on commit f25f3e2

Please sign in to comment.