summary refs log tree commit diff stats
path: root/tests/template/tparams_gensymed.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-09-05 08:21:01 +0200
committerGitHub <noreply@github.com>2019-09-05 08:21:01 +0200
commit58bcf6cd46fe9108f2dced59c612153d2951aee2 (patch)
treee485be2b109f7a75295f20faa779676ccf4f188d /tests/template/tparams_gensymed.nim
parentc2ba0ee144adfaea6f2e1cc93a20d022149f6ccf (diff)
downloadNim-58bcf6cd46fe9108f2dced59c612153d2951aee2.tar.gz
fixes #12121 (#12126)
Diffstat (limited to 'tests/template/tparams_gensymed.nim')
-rw-r--r--tests/template/tparams_gensymed.nim31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/template/tparams_gensymed.nim b/tests/template/tparams_gensymed.nim
index fe5608add..a35d878d5 100644
--- a/tests/template/tparams_gensymed.nim
+++ b/tests/template/tparams_gensymed.nim
@@ -14,6 +14,7 @@ wth
 1
 0
 (total: 6)
+S1
 '''
 """
 # bug #1915
@@ -164,3 +165,33 @@ template baz(): untyped =
   echo (total: bar2(3))
 
 baz()
+
+# bug #12121
+macro state_machine_enum(states: varargs[untyped]) =
+  result = nnkTypeSection.newTree(
+    nnkTypeDef.newTree(
+      nnkPragmaExpr.newTree(ident("State"), nnkPragma.newTree(ident("pure"))),
+      newEmptyNode(),
+      nnkEnumTy.newTree(newEmptyNode())
+    )
+  )
+
+  for s in states:
+    expectKind(s, nnkIdent)
+    result[0][2].add s
+
+template mystate_machine(body: untyped) =
+  state_machine_enum(S1, S2, S3)
+  var state_stack: seq[State]
+  template state_current(): State {.inject, used.} =
+    state_stack[^1]
+  template state_push(state_name) {.inject, used.} =
+    state_stack.add State.state_name
+  template state_pop(n = 1) {.inject, used.} =
+    state_stack.setLen(state_stack.len - n)
+  body
+
+mystate_machine:
+  state_push(S1)
+  echo state_current()
+  state_pop()