Skip to content

Commit c0045c5

Browse files
authored
CLJS-3317: PersistentVector invoke does not align with Clojure (#100)
Remove not-found case - does not exist in Clojure. Throw if k is not a number.
1 parent b68e8b5 commit c0045c5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5693,9 +5693,9 @@ reduces them without incurring seq initialization"
56935693

56945694
IFn
56955695
(-invoke [coll k]
5696-
(-nth coll k))
5697-
(-invoke [coll k not-found]
5698-
(-nth coll k not-found))
5696+
(if (number? k)
5697+
(-nth coll k)
5698+
(throw (js/Error. "Key must be integer"))))
56995699

57005700
IEditableCollection
57015701
(-as-transient [coll]

src/test/cljs/cljs/collections_test.cljs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,10 @@
10801080
(persistent! t)
10811081
(is (= :fail (try (get t :a :not-found) (catch js/Error e :fail))))))
10821082

1083+
(deftest test-cljs-3317
1084+
(testing "persistent vector invoke matches clojure"
1085+
(is (thrown-with-msg? js/Error #"Key must be integer" ([1 2] nil)))))
1086+
10831087
(comment
10841088

10851089
(run-tests)

0 commit comments

Comments
 (0)