Clojure

equality bug on records created with nested calls to map->record

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.6
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

Depending on the type of the map passed to a record map constructor, records will not correctly compare for equality:

user> (defrecord a []) 
user.a
user> (def r1 (map->a {:a 1}))
nil
user> (def r2 (map->a r1))
nil
user> (= r1 r2)  ;; expected => true
false
user> (.__extmap r1)
{:a 1}
user> (.__extmap r2)  ;; expected => {:a 1}
#user.a{:a 1}

Cause: The type of the map passed into the map constructor leaks into the __extmap, affecting equality comparison of the record. This bug was described in this post: https://groups.google.com/forum/#!topic/clojure/iN-SPBaTFUw

Approach: Clean the extmap before putting it into the record constructor.

Patch: CLJ-1388-record-equality-and-map-record-factory.patch

Screened by: Alex Miller

  1. 0001-FIX-CLJ-1388.patch
    18/Mar/14 8:44 PM
    2 kB
    Nicola Mometto
  2. CLJ-1388.patch
    29/Apr/14 1:52 PM
    6 kB
    Nicola Mometto
  3. CLJ-1388-record-equality-and-map-record-factory.patch
    29/Apr/14 10:17 AM
    5 kB
    Steve Miner
  4. CLJ-1388v2.patch
    30/Apr/14 3:57 PM
    5 kB
    Nicola Mometto

Activity

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: