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

Activity

Show:
Alex Miller
March 9, 2020, 8:57 PM

Dupe: (different scenario, same problem)

Alex Miller
August 28, 2020, 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.

Ghadi Shayban
August 31, 2020, 5:24 PM

Rescreened. a nicer approach.

Alex Miller
September 25, 2020, 7:23 PM

Released in 1.10.2-alpha2

Fixed

Assignee

Unassigned

Reporter

import

Labels

Approval

Ok

Patch

Code and Test

Fix versions

Affects versions

Priority

Minor
Configure