We're updating the issue view to help you get more done. 

= on sorted collections with different key types incorrectly throws

Description

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

1 2 3 4 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 (downstream example with clojure.data/diff)

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

Screened by: Alex Miller

Environment

None

Status

Assignee

Unassigned

Reporter

Nicola Mometto

Labels

Approval

Ok

Patch

Code and Test

Fix versions

Affects versions

Release 1.5
Release 1.6

Priority

Major