summary refs log tree commit diff stats
path: root/lib/pure/collections/sets.nim
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2021-02-08 04:47:28 -0600
committerGitHub <noreply@github.com>2021-02-08 11:47:28 +0100
commit0cf3ba159c97d3aa00bcb408e99cd4bdef33d64f (patch)
tree3a339ca3e7a368b17b327e07f084371354b5c0bd /lib/pure/collections/sets.nim
parent6f6370367b31d7e8107431f3c9568956dbea6d4e (diff)
downloadNim-0cf3ba159c97d3aa00bcb408e99cd4bdef33d64f.tar.gz
close #15767 (#16959)
* fix some warnings

* close #15767

* Revert "fix some warnings"

This reverts commit 39f2f23b0026d50c42af7be3ad80edf0f1f19610.
Diffstat (limited to 'lib/pure/collections/sets.nim')
-rw-r--r--lib/pure/collections/sets.nim9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim
index 6c9e1f558..42f8aa031 100644
--- a/lib/pure/collections/sets.nim
+++ b/lib/pure/collections/sets.nim
@@ -241,8 +241,11 @@ iterator items*[A](s: HashSet[A]): A =
   ##   assert a.len == 2
   ##   echo b
   ##   # --> {(a: 1, b: 3), (a: 0, b: 4)}
+  let length = s.len
   for h in 0 .. high(s.data):
-    if isFilled(s.data[h].hcode): yield s.data[h].key
+    if isFilled(s.data[h].hcode):
+      yield s.data[h].key
+      assert(len(s) == length, "the length of the HashSet changed while iterating over it")
 
 proc containsOrIncl*[A](s: var HashSet[A], key: A): bool =
   ## Includes `key` in the set `s` and tells if `key` was already in `s`.
@@ -901,8 +904,10 @@ iterator items*[A](s: OrderedSet[A]): A =
   ##   # --> Got 5
   ##   # --> Got 8
   ##   # --> Got 4
+  let length = s.len
   forAllOrderedPairs:
     yield s.data[h].key
+    assert(len(s) == length, "the length of the OrderedSet changed while iterating over it")
 
 iterator pairs*[A](s: OrderedSet[A]): tuple[a: int, b: A] =
   ## Iterates through (position, value) tuples of OrderedSet `s`.
@@ -913,5 +918,7 @@ iterator pairs*[A](s: OrderedSet[A]): tuple[a: int, b: A] =
       p.add(x)
     assert p == @[(0, 'a'), (1, 'b'), (2, 'r'), (3, 'c'), (4, 'd')]
 
+  let length = s.len
   forAllOrderedPairs:
     yield (idx, s.data[h].key)
+    assert(len(s) == length, "the length of the OrderedSet changed while iterating over it")