summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorJuan M Gómez <info@jmgomez.me>2023-09-30 05:27:02 +0100
committerGitHub <noreply@github.com>2023-09-30 06:27:02 +0200
commit0c179db6579ee5ae853603bf8d8efe23785cb7ab (patch)
tree2ab4e27812435c1c5f7441167726f18c52879674 /tests
parenta8d55fdec7e6e534546f9d6c116d9a76393c534b (diff)
downloadNim-0c179db6579ee5ae853603bf8d8efe23785cb7ab.tar.gz
case macro now can be used inside generic. Fixes #20435 (#22752)
fixes #20435

---------

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
Co-authored-by: Jake Leahy <jake@leahy.dev>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/macros/t20435.nim30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/macros/t20435.nim b/tests/macros/t20435.nim
new file mode 100644
index 000000000..824282198
--- /dev/null
+++ b/tests/macros/t20435.nim
@@ -0,0 +1,30 @@
+
+#[
+  A better test requires matching, so the use of @ working can be showcased
+  For example:
+
+  proc regularCase[T]() = 
+    case [(1, 3), (3, 4)]:
+    of [(1, @a), (_, @b)]:
+      echo a, b
+    else: discard
+]#
+
+{.experimental: "caseStmtMacros".}
+
+import macros
+
+type Foo = object
+
+macro `case`(obj: Foo) = quote do: discard
+
+proc notGeneric() =
+  case Foo()
+  of a b c d: discard
+
+proc generic[T]() =
+  case Foo()
+  of a b c d: discard
+
+notGeneric()
+generic[int]()