= on sorted collections with different key types incorrectly throws

Description

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

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

Activity

Show:
Daniel Compton
February 26, 2018, 8:50 AM

There is also a follow-up issue in https://dev.clojure.org/jira/browse/CLJ-2325 covering more variants of this issue.

Daniel Compton
February 21, 2018, 4:37 AM
Nicola Mometto
October 12, 2016, 11:08 AM

updated patch to fix indentation

Alex Miller
October 12, 2016, 4:46 AM

Rich: TreeSet extends AbstractSet and uses its equals() implementation - that impl checks for ClassCastException and returns null. http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/util/AbstractSet.java?av=f#96

Nicola Mometto
October 7, 2016, 9:31 PM

Updated patch to only handle equals/equiv

Completed

Assignee

Unassigned

Reporter

Nicola Mometto

Labels

Approval

Ok

Patch

Code and Test

Priority

Major

Affects versions

Fix versions