There seems to be a bug where a clause uses the :only
qualifier to ensure that a map has a specific set of keys. If the value being matched is a vector a ClassCastException
exception is thrown.
Here is an example that works as expected and does not use :only
.
(let [x []]
(match [x]
[{:k v}] :a-map
:else :not-a-map))
=> :not-a-map
If we teak it slightly to add the :only
an unexpected error is thrown.
(let [x []]
(match [x]
[({:k v} :only [:k])] :a-map
:else :not-a-map))
;; Execution error (ClassCastException) at ...
;; clojure.lang.PersistentVector cannot be cast to java.util.Map
Slack user @FiVo identified that the form produced for map patterns will perform the map checks on any value that is an ILookup
, but the checks may will include a call to .keySet
if the :only
qualifier is used.
It was suggested that the references to ILookup here be changed to IPersistentMap
. CLJ tests still pass with this change.