ClojureScript

Details

Type:
Defect

Status:
Closed

Priority:
Major

Resolution:
Completed

Affects Version/s:
None

Fix Version/s:
None

Component/s:
None

Labels:

None

Description

(def x 1)
(def y 1)
#{x y}
;= #{1 1}

This is because cljs.core.PersistentHashSet/fromArray does not check for duplicates. Clojure performs the check and throws an exception in the presence of duplicates; I'll replicate this behaviour in the forthcoming patch.

Michał Marczyk
added a comment - 04/Sep/13 2:15 AM Fix with test.
NB. if all the members are themselves literals, then we already throw at read time. This patch fixes cases like the one in the ticket description.
As a minor optimization, the runtime check for duplicates is skipped if all the member expressions of the set literal are constants.
Also, I notice that we have a similar problem with maps. I'll fix that in a separate patch (and ticket) building on this one.

NB. the desired behaviour is different: literal sets and maps are supposed to throw on duplicates, array-map is supposed to work "as if by assoc". So, I don't think there'll be much in the way of code sharing between that and this patch or CLJS-584. (Clojure uses separate PersistentArrayMap methods in the two cases.)

Michał Marczyk
added a comment - 05/Sep/13 12:07 AM I'll tackle CLJS-516, thanks for the pointer!
NB. the desired behaviour is different: literal sets and maps are supposed to throw on duplicates, array-map is supposed to work "as if by assoc". So, I don't think there'll be much in the way of code sharing between that and this patch or CLJS-584. (Clojure uses separate PersistentArrayMap methods in the two cases.)