Permalink
Browse files

CLJS-2455: nth fails on eduction

This change makes ClojureScript follow Clojure's nth's support for
sequential types that in that coercion should be attempted by calling
seq.
  • Loading branch information...
mfikes authored and swannodette committed Jan 3, 2018
1 parent 983b7fd commit cc2ad0d9a7d34973a71c3dda73e66cbbea21212e
Showing with 15 additions and 2 deletions.
  1. +4 −2 src/main/cljs/cljs/core.cljs
  2. +11 −0 src/test/cljs/cljs/core_test.cljs
@@ -1853,7 +1853,8 @@ reduces them without incurring seq initialization"
(.charAt coll n)
(throw (js/Error. "Index out of bounds")))
(implements? ISeq coll)
(or (implements? ISeq coll)
(implements? ISequential coll))
(linear-traversal-nth coll n)
(native-satisfies? IIndexed coll)
@@ -1883,7 +1884,8 @@ reduces them without incurring seq initialization"
(.charAt coll n)
not-found)
(implements? ISeq coll)
(or (implements? ISeq coll)
(implements? ISequential coll))
(linear-traversal-nth coll n not-found)
(native-satisfies? IIndexed coll)
@@ -1499,6 +1499,17 @@
(is (map-entry? (MapEntry. :key :val 0)))
(is (not (map-entry? [:key :val]))))
(deftype Foo2455 []
ISequential)
(deftest test-cljs-2455
(is (= :x (nth (eduction [:x]) 0)))
(is (thrown-with-msg? js/Error #"Index out of bounds" (nth (eduction [:x]) 1)))
(is (= :x (nth (eduction [:x]) 0 :not-found)))
(is (= :not-found (nth (eduction [:x]) 1 :not-found)))
;; Calling nth on a type satisfying ISequential should attempt coercion
(is (thrown-with-msg? js/Error #".* is not ISeqable" (nth (->Foo2455) 0))))
(deftest test-cljs-2457
(is (thrown-with-msg? js/Error #".* is not ISeqable" (seq #js {:a 1 :b 2}))))

0 comments on commit cc2ad0d

Please sign in to comment.