Skip to content

Commit 2976fa6

Browse files
committed
Add preconditions in index(before:)/index(after:)
1 parent fcaed33 commit 2976fa6

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Sources/Algorithms/Chunked.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ extension LazyChunked: LazyCollectionProtocol {
9595

9696
@inlinable
9797
public func index(after i: Index) -> Index {
98+
precondition(i != endIndex, "Can't advance past endIndex")
9899
let upperBound = i.upperBound ?? endOfChunk(startingAt: i.lowerBound)
99100
guard upperBound != base.endIndex else { return endIndex }
100101
let end = endOfChunk(startingAt: upperBound)
@@ -140,6 +141,7 @@ extension LazyChunked: BidirectionalCollection
140141

141142
@inlinable
142143
public func index(before i: Index) -> Index {
144+
precondition(i != startIndex, "Can't advance before startIndex")
143145
let start = startOfChunk(endingAt: i.lowerBound)
144146
return Index(lowerBound: start, upperBound: i.lowerBound)
145147
}

0 commit comments

Comments
 (0)