vector and subvector implement assoc-n with assoc; (assoc [0] nil 1) -> [1]
Description
PersistentVector and Subvec implement their IVector protocol (-assoc-n) with IAssociative (-assoc); it should be the other way around:
Because IVector has an additional numeric index contract that IAssociative does not. The neglected number check causes (assoc [0] nil 1) to return [1] instead of throwing an exception.
Because Java Clojure does not do this (APersistentVector.assoc does a numeric check then calls PersistentVector.assocN).
Patch attached which reverses this, and also fixes the error when a non-number is used as a key/index to assoc on PersistentVector and Subvec. Note: (assoc! (transient [0]) nil) is still broken.
PersistentVector and Subvec implement their IVector protocol (-assoc-n) with IAssociative (-assoc); it should be the other way around:
Because IVector has an additional numeric index contract that IAssociative does not. The neglected number check causes (assoc [0] nil 1) to return [1] instead of throwing an exception.
Because Java Clojure does not do this (
APersistentVector.assoc
does a numeric check then callsPersistentVector.assocN
).See comments in https://clojure.atlassian.net/browse/CLJS-728#icft=CLJS-728 for more detailed rationales.
Patch attached which reverses this, and also fixes the error when a non-number is used as a key/index to
assoc
onPersistentVector
andSubvec
. Note: (assoc! (transient [0]) nil) is still broken.