summary refs log tree commit diff stats
path: root/lib/core
diff options
context:
space:
mode:
authorDankr4d <dude569@freenet.de>2021-08-25 19:27:00 +0200
committerGitHub <noreply@github.com>2021-08-25 17:27:00 +0000
commitc70e4040bd69e1ee32b6c676dbfc763c7cf4df37 (patch)
treea0265f944fac5a46d14cac1a65808d540ffefb98 /lib/core
parent3aa16c1de00c723d48e48fe3fdf07a276d1b4b6a (diff)
downloadNim-c70e4040bd69e1ee32b6c676dbfc763c7cf4df37.tar.gz
fixes #14511 [backport:1.4] (#18732)
* fixes #14511 [backport:1.4]

Signed-off-by: Dankr4d <dude569@freenet.de>

* Replaced fix with code from alaviss, for better readability, with small
changes.

Signed-off-by: Dankr4d <dude569@freenet.de>

* - Specified output in test.

Signed-off-by: Dankr4d <dude569@freenet.de>

* Replaced case in nnkRecCase with a simpler version, which just adds the
last son.

Signed-off-by: Dankr4d <dude569@freenet.de>

* Update tests/macros/t14511.nim

* Update tests/macros/t14511.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Diffstat (limited to 'lib/core')
-rw-r--r--lib/core/macros.nim21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index 645f5067a..806ea7e31 100644
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -1541,18 +1541,17 @@ proc customPragmaNode(n: NimNode): NimNode =
         for i in 0..<identDefsStack.len: identDefsStack[i] = obj[2][i]
         while identDefsStack.len > 0:
           var identDefs = identDefsStack.pop()
-          if identDefs.kind == nnkRecCase:
-            identDefsStack.add(identDefs[0])
-            for i in 1..<identDefs.len:
-              let varNode = identDefs[i]
-              # if it is and empty branch, skip
-              if varNode[0].kind == nnkNilLit: continue
-              if varNode[1].kind == nnkIdentDefs:
-                identDefsStack.add(varNode[1])
-              else: # nnkRecList
-                for j in 0 ..< varNode[1].len:
-                  identDefsStack.add(varNode[1][j])
 
+          case identDefs.kind
+          of nnkRecList:
+            for child in identDefs.children:
+              identDefsStack.add(child)
+          of nnkRecCase:
+            # Add condition definition
+            identDefsStack.add(identDefs[0])
+            # Add branches
+            for i in 1 ..< identDefs.len:
+              identDefsStack.add(identDefs[i].last)
           else:
             for i in 0 .. identDefs.len - 3:
               let varNode = identDefs[i]