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

0 votes
in core.match by
When matching map values via regular expressions with a key that does not exist in the map, {{core.match}} throws an exception. Here is an example:

{code:none}
(= 2 (match {:foo "bar"}
            {:bar #"bar"} 1
            :else 2))))
 

throws

{code:none}
java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.lang.CharSequence
 at clojure.core$re_matcher.invoke (core.clj:4460)
    clojure.core$re_matches.invoke (core.clj:4497)
...
 

because {{re-match}} gets called with the {{:clojure.core.match/not-found}} keyword since the key was not found.

The attached patch contains a test case for the problem and offers a fix by making sure that {{re-match}} only gets called when the key was found and fails the match gently otherwise.

3 Answers

0 votes
by

Comment made by: glchapman

I think this is basically a special case of MATCH-105

0 votes
by

Comment made by: crestani

Yes, you are right. (link: https://dev.clojure.org/jira/browse/MATCH-105 text: MATCH-105) is more robust and should be applied.

0 votes
by
Reference: https://clojure.atlassian.net/browse/MATCH-123 (reported by alex+import)
...