summary refs log tree commit diff stats
path: root/compiler/semgnrc.nim
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 /compiler/semgnrc.nim
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 'compiler/semgnrc.nim')
-rw-r--r--compiler/semgnrc.nim16
1 files changed, 15 insertions, 1 deletions
diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim
index aa05f8d85..eebf11c0a 100644
--- a/compiler/semgnrc.nim
+++ b/compiler/semgnrc.nim
@@ -188,6 +188,18 @@ proc addTempDecl(c: PContext; n: PNode; kind: TSymKind) =
   styleCheckDef(c, n.info, s, kind)
   onDef(n.info, s)
 
+proc addTempDeclToIdents(c: PContext; n: PNode; kind: TSymKind; inCall: bool) =
+  case n.kind 
+  of nkIdent:
+    if inCall:
+      addTempDecl(c, n, kind)
+  of nkCallKinds:
+    for s in n:
+      addTempDeclToIdents(c, s, kind, true)  
+  else:
+    for s in n:
+      addTempDeclToIdents(c, s, kind, inCall)
+
 proc semGenericStmt(c: PContext, n: PNode,
                     flags: TSemGenericFlags, ctx: var GenericCtx): PNode =
   result = n
@@ -360,7 +372,9 @@ proc semGenericStmt(c: PContext, n: PNode,
       var a = n[i]
       checkMinSonsLen(a, 1, c.config)
       for j in 0..<a.len-1:
-        a[j] = semGenericStmt(c, a[j], flags, ctx)
+        a[j] = semGenericStmt(c, a[j], flags+{withinMixin}, ctx)
+        addTempDeclToIdents(c, a[j], skVar, false)
+
       a[^1] = semGenericStmtScope(c, a[^1], flags, ctx)
     closeScope(c)
   of nkForStmt, nkParForStmt: