Var type implements IEquiv but not IHash

Description

The Var type implements IEquiv based on the var's symbol, but not IHash. That means that two vars with the same symbol compare equal but don't hash equal, which will cause strange results if you put them in a hash-{map,set}:

cljs.user=> (def foo "bar")
#'cljs.user/foo
cljs.user=> (= #'foo #'foo)
true
cljs.user=> (= (hash #'foo) (hash #'foo))
false

Patch forthcoming.

Environment

Tested on OS X 10.11, Chrome.

Activity

Show:
Christopher Vermilion
April 27, 2016, 4:41 AM

Patch note: The patch fixes the issue but I haven't added a test. It didn't seem like the hash behavior of basic types was tested in general, but moreover while I think this behavior is desirable I'm not sure it should be guaranteed. Happy to write a test if that would be useful.

Christopher Vermilion
April 27, 2016, 4:48 AM

Aside for the curious on how this came up at all: the Schema library uses Vars to specify recursive schemas, and does internal caching by with a map keyed by schemas themselves. If you defined the same recursive schema multiple times, the results would be unpredictable, since two equivalent recursive schemas would compare equal but wouldn't necessarily be interchangeable as map keys.

David Nolen
May 6, 2016, 7:42 PM

Chris have you submitted your CA yet?

Christopher Vermilion
May 6, 2016, 8:02 PM
Completed

Assignee

David Nolen

Reporter

Christopher Vermilion

Labels

Approval

None

Patch

Code

Affects versions

Priority

Minor