pr broken for sorted maps or structmaps containing namespaced keys when *print-namespace-maps*

Description

pr misrepresents a structmap containing namespaced-keyword keys. pr misstates actual keys' values, and includes phantom keys.

It worked in Clojure 1.8, and disabling the print-namespace-maps feature appears to work around the problem:

Similar can also occur in sorted maps, or in other map-likes that don't respond well with `empty` (in particular, maps that have expected seq orders based on the keys). See CLJ-2537.

Cause: The implementation of namespace map printing relies on extracting the namespace prefix (when applicable), stripping that prefix from keys, and rebuilding the map with `empty`. For maps other than PHM, this can fail.

Approach: clj-2469-3.patch alters this to instead build a seq-ordered kv vector to retain order. It also adds many tests for various namespace map printing that were missing, including some new ones for this ticket and CLJ-2537.

Another option (not taken here) would be to only print namespace maps with PAM/PHM - this could probably be handled polymorphically in the print methods.

Patch: clj-2469-3.patch

Screened by: Ghadi

Environment

None

Attachments

3

Activity

Show:

Alex Miller September 25, 2020 at 7:23 PM

Released in 1.10.2-alpha2

Ghadi Shayban August 31, 2020 at 5:24 PM

Rescreened. a nicer approach.

Alex Miller August 28, 2020 at 6:00 PM

I thought about this some more and added a new -3 patch that does not build a PAM to retain order but just passes the kv seq through, which has the same effect but without building an unnecessary collection. I think this is an improvement over the previous patch, so ready to re-screen.

Alex Miller March 9, 2020 at 8:57 PM

Dupe: (different scenario, same problem)

Fixed

Details

Assignee

Reporter

Approval

Ok

Patch

Code and Test

Priority

Affects versions

Fix versions

Created January 21, 2019 at 3:41 AM
Updated September 25, 2020 at 7:23 PM
Resolved September 25, 2020 at 7:23 PM