summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/pure/collections/sets.nim42
-rw-r--r--tests/sets/m17385.nim11
-rw-r--r--tests/sets/t17385.nim4
3 files changed, 36 insertions, 21 deletions
diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim
index ef2e92275..3f91d9030 100644
--- a/lib/pure/collections/sets.nim
+++ b/lib/pure/collections/sets.nim
@@ -164,6 +164,27 @@ proc contains*[A](s: HashSet[A], key: A): bool =
   var index = rawGet(s, key, hc)
   result = index >= 0
 
+proc len*[A](s: HashSet[A]): int =
+  ## Returns the number of elements in `s`.
+  ##
+  ## Due to an implementation detail you can call this proc on variables which
+  ## have not been initialized yet. The proc will return zero as the length
+  ## then.
+  runnableExamples:
+    var a: HashSet[string]
+    assert len(a) == 0
+    let s = toHashSet([3, 5, 7])
+    assert len(s) == 3
+
+  result = s.counter
+
+proc card*[A](s: HashSet[A]): int =
+  ## Alias for `len() <#len,HashSet[A]>`_.
+  ##
+  ## Card stands for the `cardinality
+  ## <http://en.wikipedia.org/wiki/Cardinality>`_ of a set.
+  result = s.counter
+
 proc incl*[A](s: var HashSet[A], key: A) =
   ## Includes an element `key` in `s`.
   ##
@@ -357,27 +378,6 @@ proc clear*[A](s: var HashSet[A]) =
     s.data[i].hcode = 0
     s.data[i].key = default(typeof(s.data[i].key))
 
-proc len*[A](s: HashSet[A]): int =
-  ## Returns the number of elements in `s`.
-  ##
-  ## Due to an implementation detail you can call this proc on variables which
-  ## have not been initialized yet. The proc will return zero as the length
-  ## then.
-  runnableExamples:
-    var a: HashSet[string]
-    assert len(a) == 0
-    let s = toHashSet([3, 5, 7])
-    assert len(s) == 3
-
-  result = s.counter
-
-proc card*[A](s: HashSet[A]): int =
-  ## Alias for `len() <#len,HashSet[A]>`_.
-  ##
-  ## Card stands for the `cardinality
-  ## <http://en.wikipedia.org/wiki/Cardinality>`_ of a set.
-  result = s.counter
-
 
 proc union*[A](s1, s2: HashSet[A]): HashSet[A] =
   ## Returns the union of the sets `s1` and `s2`.
diff --git a/tests/sets/m17385.nim b/tests/sets/m17385.nim
new file mode 100644
index 000000000..3919e067a
--- /dev/null
+++ b/tests/sets/m17385.nim
@@ -0,0 +1,11 @@
+import std/sets
+
+type
+  Diff*[T] = object
+    data: T
+
+proc test*[T](diff: Diff[T]) =
+  var bPopular = initHashSet[T]()
+  for element in bPopular.items():
+    echo element
+
diff --git a/tests/sets/t17385.nim b/tests/sets/t17385.nim
new file mode 100644
index 000000000..cc08b4882
--- /dev/null
+++ b/tests/sets/t17385.nim
@@ -0,0 +1,4 @@
+import m17385
+
+let a = Diff[int]()
+a.test()