Skip to content

Commit 2188ebe

Browse files
som-snyttsteinybot
andcommitted
Empty iterator must not mutate
Co-authored-by: steinybot <jasonpickensnz@gmail.com>
1 parent e3c1618 commit 2188ebe

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/src/scala/collection/immutable/TreeSeqMap.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,11 @@ object TreeSeqMap extends MapFactory[TreeSeqMap] {
392392

393393
if (it != Zero) push(it)
394394

395-
def hasNext = index != 0
395+
def hasNext = index > 0
396396
@tailrec
397397
def next(): V =
398-
pop match {
398+
if (!hasNext) scala.collection.Iterator.empty.next()
399+
else pop match {
399400
case Bin(_,_, Tip(_, v), right) =>
400401
push(right)
401402
v

0 commit comments

Comments
 (0)