Skip to content

Commit 892ed20

Browse files
committed
CLJS-2798: ChunkCons -next doesn't handle nil more
This revison aligns more with the Clojure implementation. In the Clojure implemenentation, if _more is nil, then it would end up doing a seq on an empty list, which would produce nil. This revision simply pre-checks if more is nil, and if not, returns nil in that case. The change also eliminates an unnecessary check of the return value of -seq (checking for nil and returning nil), and just returns the value -seq produces.
1 parent e173e54 commit 892ed20

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/main/cljs/cljs/core.cljs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,9 +3553,8 @@ reduces them without incurring seq initialization"
35533553
(-next [coll]
35543554
(if (> (-count chunk) 1)
35553555
(ChunkedCons. (-drop-first chunk) more meta nil)
3556-
(let [more (-seq more)]
3557-
(when-not (nil? more)
3558-
more))))
3556+
(when-not (nil? more)
3557+
(-seq more))))
35593558

35603559
IChunkedSeq
35613560
(-chunked-first [coll] chunk)

src/test/cljs/cljs/collections_test.cljs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,11 @@
10191019
(is (not (map-entry? coll)))
10201020
(is (= [:a 1] coll)))))
10211021

1022+
(deftest test-cljs-2798
1023+
(is (nil? (let [b (chunk-buffer 1)]
1024+
(chunk-append b 0)
1025+
(next (chunk-cons (chunk b) nil))))))
1026+
10221027
(comment
10231028

10241029
(run-tests)

0 commit comments

Comments
 (0)