Uploaded image for project: 'Clojure'
  1. CLJ-1242

= on sorted collections with different key types incorrectly throws

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: Release 1.6, Release 1.5
    • Fix versions: Release 1.9
    • Labels:
    • Approval:
      Ok
    • Patch:
      Code and Test

      Description

      Comparing a sorted-set with numbers to a set with keywords is not symmetric:

      user=> (= #{:a} (sorted-set 1))
      false
      user=> (= (sorted-set 1) #{:a})
      ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword  clojure.lang.Keyword.compareTo (Keyword.java:109)
      

      The latter case should return false instead of throwing.

      Cause: APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check.

      Proposed: It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.

      See also: CLJ-1983 Closed (downstream example with clojure.data/diff)

      Patch: 0001-CLJ-1242-equals-doesn-t-throw-on-sorted-collections.patch

      Screened by: Alex Miller

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              bronsa Nicola Mometto
            • Votes:
              4 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: