Affects Version/s: Release 1.9
Fix Version/s: None
Patch:Code and Test
This came up on Slack. A naïve implementation of "lispify" to turn vectors into lists used this code:
But when called like this:
It produces this error: java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.util.Map$Entry
My initial reaction was to change the condition to (and (vector? e) (not (map-entry? e))) but that still failed, because while walking the hash map, the MapEntry [:a "b"] was turned into a PersistentVector.
At this point, we can switch to using prewalk and it works as expected:
Now we get the expected result:
This seems unintuitive at best and feels like a bug: postwalk should preserve the MapEntry type rather than converting it to a PersistentVector.
The problem seems to be this line https://github.com/clojure/clojure/blob/master/src/clj/clojure/walk.clj#L45:
Would it be reasonable for this to become:
This would preserve the type of the subelement.
Prescreened by: Alex Miller