Skip to content

Commit 0988738

Browse files
committed
CLJ-2718 Fix bug in drop of repeat that goes to or past end of sequence
1 parent ca1768b commit 0988738

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/jvm/clojure/lang/Repeat.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,15 @@ public Object reduce(IFn f, Object start){
100100
}
101101

102102
public Sequential drop(int n) {
103-
if(count > 1) {
104-
return new Repeat(count-n, val);
105-
} else if(count == INFINITE) {
103+
if(count == INFINITE) {
106104
return this;
107105
} else {
108-
return null;
106+
long droppedCount = count-n;
107+
if(droppedCount > 0) {
108+
return new Repeat(droppedCount, val);
109+
} else {
110+
return null;
111+
}
109112
}
110113
}
111114

test/clojure/test_clojure/sequences.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,12 @@
10031003
() '(1 2)
10041004
[] [1 2]
10051005
{} {:a 1 :b 2}
1006-
#{} #{1 2} ))
1006+
#{} #{1 2})
1007+
1008+
; CLJ-2718
1009+
(is (= '(:a) (drop 1 (repeat 2 :a))))
1010+
(is (= () (drop 2 (repeat 2 :a))))
1011+
(is (= () (drop 3 (repeat 2 :a)))))
10071012

10081013
(defspec longrange-equals-range 1000
10091014
(prop/for-all [start gen/int

0 commit comments

Comments
 (0)