summary refs log tree commit diff stats
path: root/tests/sets
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2024-03-28 18:04:47 +0800
committerGitHub <noreply@github.com>2024-03-28 11:04:47 +0100
commit4b6a9e4add2af2a458d171b23030acb5d1c70ecb (patch)
treef5ed3603cc1d4154c3757b2bf47905ddf9f0f228 /tests/sets
parenta24990bd8cca735fa1805279a7cd3f42e22240cd (diff)
downloadNim-4b6a9e4add2af2a458d171b23030acb5d1c70ecb.tar.gz
fixes #23422; card regression (#23437)
fixes #23422

ref https://github.com/nim-lang/Nim/issues/20997
https://github.com/nim-lang/Nim/pull/21165

The function `cardSet` is used for large sets that are stored in the
form of arrays. It shouldn't be passed as a pointer
Diffstat (limited to 'tests/sets')
-rw-r--r--tests/sets/tsets.nim38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/sets/tsets.nim b/tests/sets/tsets.nim
index 3c20a3907..0d28091c2 100644
--- a/tests/sets/tsets.nim
+++ b/tests/sets/tsets.nim
@@ -1,3 +1,7 @@
+discard """
+  target: "c cpp"
+"""
+
 # Test builtin sets
 
 # xxx these tests are not very good, this should be revisited.
@@ -93,3 +97,37 @@ block:
 
   doAssert k99 notin s1
   doAssert k99 notin s2
+
+block: # bug #23422
+  block:
+    var a: set[uint8] = {1'u8}
+
+    proc printLen(x: set[uint8]): int =
+      doAssert x.len == card(x)
+      result = card(x)
+
+    proc printLenVar(x: var set[uint8]): int =
+      doAssert x.len == card(x)
+      result = card(x)
+
+    doAssert a.len == 1
+    doAssert printLen(a) == 1
+    doAssert printLenVar(a) == card(a)
+
+  block:
+    type Fruit = enum
+      Apple, Banana, Melon
+
+    var a: set[Fruit] = {Apple}
+
+    proc printLen(x: set[Fruit]): int =
+      doAssert x.len == card(x)
+      result = card(x)
+
+    proc printLenVar(x: var set[Fruit]): int =
+      doAssert x.len == card(x)
+      result = card(x)
+
+    doAssert a.len == 1
+    doAssert printLen(a) == 1
+    doAssert printLenVar(a) == card(a)